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 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 |
function getRoles(): Promise<Array<Role>>;
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"
* }
* ]
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.