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¶
- (void)getUserRolesWithResponseHandler:^(NSArray<NSString *> * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func getUserRoles(responseHandler: (([String]) -> Void)!, errorHandler: ((Fault) -> Void)!)
where
Argument | Description |
---|---|
responseHandler |
Handles successful result of an asynchronous call. |
errorHandler |
Handles fault result of an asynchronous call. |
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.
[Backendless.shared.userService loginWithIdentity:@"alice@yourmail.com" password:@"wonderland" responseHandler:^(BackendlessUser *loggedInUser) {
[Backendless.shared.userService getUserRolesWithResponseHandler:^(NSArray<NSString *> *roles) {
for (NSString *role in roles) {
NSLog(@"role: %@", role);
}
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.userService.login(identity: "alice@yourmail.com", password: "wonderland", responseHandler: { loggedInUser in
Backendless.shared.userService.getUserRoles(responseHandler: { roles in
for role in roles {
print("role: \(role)")
}
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
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: