Retrieving Available User Roles¶
Description¶
This operation returns a list of the roles associated with the user account currently logged in to the Backendless application. If the request is sent without logging in, the system will return only one role - NotAuthenticatedUser
.
Method¶
Non-blocking Method 1: With the Callback:
public void Backendless.UserService.GetUserRoles( AsyncCallback<IList<string>> callback )
Non-blocking Method 2:
public async Task<IList<string>> IList<String> userRoles = await Backendless.UserService.GetUserRolesAsync();
Blocking API
public List<String> Backendless.UserService.GetUserRoles();
where
Argument | Description |
---|---|
callback |
an object which is notified when the server returns a list of user roles or an error. |
Return Value¶
Returns an array of roles assigned to the currently logged in user
[
"roleName 1",
"roleName 2"
...
"roleName N"
]
Example¶
The example below logs in as "alice@wonderland.com"
, and retrieves the current user roles as an array containing string values.
**Non-blocking Method 1: With the Callback **
Backendless.UserService.Login("alice@yourmail.com", "wonderland");
Backendless.UserService.GetUserRoles(new AsyncCallback<IList<string>>(
response =>
{
foreach (string role in response)
{
Debug.Log($"UserRole: {role}\n");
}
},
fault =>
{
throw new BackendlessException(fault);
}
));
Non-blocking Method 2:
Backendless.UserService.Login("alice@yourmail.com", "wonderland");
IList<String> userRoles = await Backendless.UserService.GetUserRolesAsync();
foreach (String role in userRoles)
Console.WriteLine($"User role: {role}");
Blocking API¶
static void GetUserRoles()
{
Backendless.UserService.Login("alice@yourmail.com", "wonderland");
IList<String> userRoles = Backendless.UserService.GetUserRoles();
foreach( String roleName in userRoles )
System.Console.WriteLine( roleName );
}
When retrieving available roles without logging in, the server returns only one role - NotAuthenticatedUser.
Codeless Reference¶
Returns a list containing current user roles.
Consider the following record in the Users
data table:
The example below logs in as "alice@wonderland.com"
, and retrieves the current user roles as a list containing string values.
The output will look as shown below after the Codeless logic runs: