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¶
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:
Suppose, the identity "alice@yourmail.com"
has the following assigned roles:
The example below unassigns the "Team Leader"
role from the "alice@yourmail.com"
identity.
After the Codeless logic runs, the "Team Leader"
role gets unassigned: