Unassign a role from a user with the Node.js SDK
permit.api.users.unassignRole() removes a role that a user holds in a tenant of the Permit.io environment that your Node.js SDK client is connected to. This reference is for backend developers who revoke roles from code.
Prerequisites
- A
permitclient created with an API key for the environment. See Create a Permit client. - A role assignment to remove. See Assign a role to a user with the Node.js SDK.
Method signature
| Method | Signature | Status |
|---|---|---|
permit.api.users.unassignRole | unassignRole(unassignment: RoleAssignmentRemove): Promise<void> | Recommended |
permit.api.unassignRole | unassignRole(removedRole: RoleAssignmentRemove): Promise<AxiosResponse<void>> | Deprecated alias |
Parameters
The method takes one argument: a RoleAssignmentRemove object. Pass the object itself, not a JSON string.
| Field | Type | Required | Description |
|---|---|---|---|
user | string | Yes | Key or ID of the user who loses the role. |
role | string | Yes | Key or ID of the role to remove. |
tenant | string | Yes | Key or ID of the tenant in which the user holds the role. |
resource_instance | string | No | Resource instance of an instance-level role, as an ID or in the format resource_type:resource_instance_key. |
Example RoleAssignmentRemove object:
{
role: "role",
tenant: "tenant",
user: "user"
}
Example
await permit.api.users.unassignRole(unassignedRole);
Return value
permit.api.users.unassignRole() resolves to undefined when the role assignment is removed. The deprecated permit.api.unassignRole() resolves to the Axios response of the delete request.
If the Permit API returns an error status code, permit.api.users.unassignRole() throws a PermitApiError. The deprecated permit.api.unassignRole() rethrows the underlying Axios error.