Skip to content

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

Future<List<String>> Backendless.userService.getUserRoles();

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.

Before retrieving the user roles, log in as described in the Login section. Then, retrieve the user roles as follows:

//login user 
Backendless.userService.login("alice@yourmail.com", "wonderland").then((backendlessUser) {
  // user has been logged in. Get user roles. 
  Backendless.userService.getUserRoles().then((userRoles) {
    //here we get all user roles - "userRoles". 
  });
});

Codeless Reference

user_service_codeless_get_user_roles

Returns a list containing current user roles.

Consider the following record in the Users data table:
user_service_codeless_example_get_user_roles_example_1

The example below logs in as "alice@wonderland.com", and retrieves the current user roles as a list containing string values.

user_service_codeless_example_get_user_roles_example_2

The output will look as shown below after the Codeless logic runs:

user_service_codeless_example_get_user_roles_example_3