getRoles( )
Retrieves the member's roles.
Description
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 Identity | Promise Resolves To |
---|---|
Logged-in member | Array of member roles |
Site owner or contributor with admin permissions | Array of member roles, plus an additional role where name is Admin |
Anyone else | Promise is rejected |
Syntax
function getRoles(): Promise<Array<Role>>
getRoles Parameters
This function does not take any parameters.
Returns
Fulfilled - List of roles. Rejected - If no member is currently logged in.
Return Type:
NAME
TYPE
DESCRIPTION
Role ID.
Role name as defined in the site's
Member Permissions
page or one of "Admin"
or "Member"
.
Role description, if defined in the site's dashboard.
Role color, as defined in the site's Member Permissions page.
One of:
"DARK_BLUE"
"LIGHT_BLUE"
"TEAL"
"LIGHT_GREEN"
"YELLOW"
"ORANGE"
"RED"
"VIOLET"
"PURPLE"
Date and time the role was created.
Was this helpful?
Get the currently logged-in member's roles
1import { Permissions, webMethod } from 'wix-web-module';2import { currentMember } from 'wix-members-backend';34export const myGetRolesFunction = webMethod(Permissions.Anyone, () => {5 return currentMember.getRoles()6 .then((roles) => {7 return roles;8 })9 .catch((error) => {10 console.error(error);11 });12});1314/* Promise resolves to:15 * [16 * {17 * "_id": "42082477-9616-4f15-bf1d-64b2b3049a42",18 * "_createdDate": "2021-01-31T23:26:56.089Z",19 * "title": "Forum Gatekeeper",20 * "description": "Can approve or block members, close discussions, and delete posts",21 * "color": "LIGHT_GREEN"22 * },23 * {24 * "_id": "9c3501b4-b8e0-4970-8795-d8ecfea698b7",25 * "_createdDate": "2021-01-31T23:26:17.535Z",26 * "title": "Forum Mod",27 * "description": "Can approve posts from new members and lock discussions",28 * "color": "VIOLET"29 * },30 * {31 * "_id": "00000000-0000-0000-0000-000000000001",32 * "title": "Admin",33 * "color": "DARK_BLUE"34 * }35 * ]36 */