Skip to content

Unassigning a Role from a User

Description

Users may have different roles, and in some cases you may want to unassign a specific role from the user by invoking the operation described in this topic.

This operation is available only from Custom Business Logic. Applications must use the "CloudCode API key" in order for the API call to be  accepted on the server. The reason for this restriction is that a malicious use of this API can easily compromise application's security. As a result, this API must be used from a controlled environment.

Method

Backendless.UserService.unassignRole(identity, roleName): Promise<void>;

where:

Argument                Description
identity value for a user property marked as identity. String value.
roleName the name of the role to remove from the user account. String value.

Return Value

None

Example

The example below unassigns a role "TrialUser" from the "alice@yourmail.com" identity.

Backendless.UserService.unassignRole( "alice@yourmail.com", "TrialUser" )
 .then( function() {
  })
 .catch( function( error ) {
  });

The following errors may occur during the API calls described above. See the Error Handling section for details on how to retrieve the error code when the server returns an error.

Error Code
Description
2002
Version is disabled or provided wrong application info (application id or secret key)
2005
Could not find role.
3038
One of the required parameters (user identity or roleName) is null.
3057
Could not find user by id or identity.
3058
Could not assign role to user.
3059
Could not unassign role to user.

CloudCode Codeless Reference

user_service_codeless_unassign_user_roles

where:

Argument                Description
identity A value for a column in the Users table marked as identity. By default the column marked as identity isemail, however, it can be changed to another column in Backendless Console.
role name The name of the role to be unassigned from the specified identity.

Important

This Codeless block is only available in CloudCode due to the security reasons. If this operation is exposed to users, then your application can be compromised.

This operation does not return a value.

Consider the following record in the Users data table:

user_service_codeless_example_get_user_roles_example_1

Suppose, the identity "alice@yourmail.com" has the following assigned roles:

user_service_codeless_example_assign_a_role_3

The example below unassigns the "Team Leader" role from the "alice@yourmail.com"identity.

user_service_codeless_example_unassign_user_roles

After the Codeless logic runs, the "Team Leader" role gets unassigned:

user_service_codeless_example_assign_a_role_1