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 { currentMember } from 'wix-members-backend';23export function myGetRolesFunction() {4 return currentMember.getRoles()5 .then((roles) => {6 return roles;7 })8 .catch((error) => {9 console.error(error);10 });11}1213/* Promise resolves to:14 * [15 * {16 * "_id": "42082477-9616-4f15-bf1d-64b2b3049a42",17 * "_createdDate": "2021-01-31T23:26:56.089Z",18 * "title": "Forum Gatekeeper",19 * "description": "Can approve or block members, close discussions, and delete posts",20 * "color": "LIGHT_GREEN"21 * },22 * {23 * "_id": "9c3501b4-b8e0-4970-8795-d8ecfea698b7",24 * "_createdDate": "2021-01-31T23:26:17.535Z",25 * "title": "Forum Mod",26 * "description": "Can approve posts from new members and lock discussions",27 * "color": "VIOLET"28 * },29 * {30 * "_id": "00000000-0000-0000-0000-000000000001",31 * "title": "Admin",32 * "color": "DARK_BLUE"33 * }34 * ]35 */