Search...
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.
Notes:
- The member data in the resolved promise will only include custom fields from your site's contacts if they are added to your site Members in your site's dashboard.
- 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:
Promise<Array<Role>>
NAME
TYPE
DESCRIPTION
_id
string
Role ID.
title
string
Role name as defined in the site's
Member Permissions
page or one of "Admin"
or "Member"
.
description
string
Role description, if defined in the site's dashboard.
color
string
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"
_createdDate
Date
Date and time the role was created.
Was this helpful?
Get the currently logged-in member's roles
Copy Code
1import { currentMember } from 'wix-members-frontend';23// ...45currentMember.getRoles()6 .then((roles) => {7 return roles;8 })9 .catch((error) => {10 console.error(error);11 });1213/* Returned roles array: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 */