Assigning a Role to a User¶
Description¶
This operation assigns a new role to a user.
This functionality can be used only in CloudCode (Java, JS or Codeless), 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.assignRole(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 assign to the user. String value. |
Return Value¶
None.
Example¶
The example below assigns a new role "TrialUser"
to "alice@yourmail.com"
identity.
Backendless.UserService.assignRole( "alice@yourmail.com", "TrialUser" )
.then( function() {
})
.catch( function( error ) {
});
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 а role that must be assigned. |
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 assigns a new role "Team Leader"
to the "alice@yourmail.com"
identity.
The result of this operation is a new assigned role "Team Leader"
: