assignRole( )
Assigns a role to a member.
Description
The assignRole()
function returns a Promise that resolves when the
specified role is assigned to the specified member.
Note: This function replaces the deprecated
wix-users-backend.roles.assignRole()
. The deprecated function will continue to work, but it will not receive updates. To keep any existing code compatible with future changes, see the migration instructions.
roleId
must be an ID from an existing role in your site.
The role ID can be copied from the Role Settings page.
You can access the Role Settings page from your site's
Member Permissions
page.
Note: This function may take a few seconds until the role is assigned and the promise is resolved.
Syntax
function assignRole(roleId: string, memberId: string, [options: AuthOptions]): Promise<void>
assignRole Parameters
NAME
TYPE
DESCRIPTION
ID of the role to assign to the member.
ID of the member to assign the role to.
Authorization options.
Returns
Fulfilled - When the role is assigned to the member. Rejected - Error message.
Return Type:
Was this helpful?
Assign a role to a member
1import { authorization } from 'wix-members-backend';23export function myAssignRoleFunction() {4 const roleId = "b62310c1-1c81-4ca9-9fe9-42b48f6e164e";5 const memberId = "72751428-2743-4bda-acf5-4218a4279cd3";6 const options = {7 suppressAuth: false8 };910 return authorization.assignRole(roleId, memberId, options)11 .then(() => {12 console.log("Role assigned to member");13 })14 .catch((error) => {15 console.error(error);16 });17}