updateRoleApi - n1lby73/industrial-IOT GitHub Wiki

Overview

The Update User Role API endpoint allows authorized users with owner privileges to modify the role of another user in the system. This endpoint necessitates authentication through a JSON Web Token (JWT) and enables the promotion or demotion of users by specifying their email and the new role (either "user" or "admin"). It allows for the promotion and demotion of users based on the specified role, facilitating efficient management of user roles within the system.

Endpoint URL

  • URL: https://industrialiot.onrender.com/api/updaterole
  • Method:PUT

Request Parameters

  • Headers:

    • Authorization: Bearer <ACCESS_TOKEN>
    • Content-Type: application/json
  • Body Parameters:
Parameter Type Description
email String User's email (required)
role String New role (user/admin) (required)

Responses

  • Success Response:

    • Status Code: 200 OK
    • Response Body:
      {
        "success": "User's role has been updated successfully"
      }
      • Description: Indicates that the user's role has been updated successfully.
  • Error Responses:

    • Status Code: 400 Bad Request

      • Response Body:
        {
            "Error": "Invalid Email"
        }
      • Description: Indicates an invalid or unrecognized email provided.
    • Status Code: 400 Bad Request

      • Response Body:
        {
            "Error": "User has not verified their email"
        }
      • Description: Indicates that the user's email has not been verified.
    • Status Code: 400 Bad Request

      • Response Body:
        {
            "Error": "Unknown role"
        }
      • Description: Indicates an unrecognized or unsupported role provided.
    • Status Code: 304 Not Modified

      • Response Body:
        {
            "Msg": "Role not updated but same"
        }
      • Description: Indicates that the user's role remains the same as the updated role.

Usage

  1. Request Method: PUT

  2. Endpoint URL: https://industrialiot.onrender.com/api/updaterole

  3. Header:

     Authorization: Bearer <JWT>
     Content-Type: application/json
  4. Request Body:

    {
        "email": "[email protected]",
        "role": "<NEW_ROLE>"
    }

    Note: The role field in the request body should only contain either "admin" or "user" to represent the desired role, facilitating either the promotion or demotion of users within the system.

⚠️ **GitHub.com Fallback** ⚠️