getRoles( )


Retrieves the member's roles.

The getRoles() function returns a Promise that resolves to the roles of the currently logged-in member. If no member is currently logged in, the Promise is rejected.

Note: The APIs in CurrentMember are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The following results are returned depending on the session identity:

Session IdentityPromise Resolves To
Logged-in memberArray of member roles
Site owner or contributor with admin permissionsArray of member roles, plus an additional role where name is Admin
Anyone elsePromise is rejected
Method Declaration
Copy
function getRoles(): Promise<Array<Role>>;
Request
This method does not take any parameters
Returns
Return Type:Promise<Array<Role>>
Get the currently logged-in member's roles
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { currentMember } from "wix-members-backend"; export const myGetRolesFunction = webMethod(Permissions.Anyone, () => { return currentMember .getRoles() .then((roles) => { return roles; }) .catch((error) => { console.error(error); }); }); /* Promise resolves to: * [ * { * "_id": "42082477-9616-4f15-bf1d-64b2b3049a42", * "_createdDate": "2021-01-31T23:26:56.089Z", * "title": "Forum Gatekeeper", * "description": "Can approve or block members, close discussions, and delete posts", * "color": "LIGHT_GREEN" * }, * { * "_id": "9c3501b4-b8e0-4970-8795-d8ecfea698b7", * "_createdDate": "2021-01-31T23:26:17.535Z", * "title": "Forum Mod", * "description": "Can approve posts from new members and lock discussions", * "color": "VIOLET" * }, * { * "_id": "00000000-0000-0000-0000-000000000001", * "title": "Admin", * "color": "DARK_BLUE" * } * ] */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?