Search.../

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.

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - When the role is assigned to the member. Rejected - Error message.

Returns an empty object.

Status/Error Codes

Was this helpful?

Assign a role to a member

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { authorization } from 'wix-members-backend';
3
4export const myAssignRoleFunction = webMethod(Permissions.Anyone, () => {
5 const roleId = "b62310c1-1c81-4ca9-9fe9-42b48f6e164e";
6 const memberId = "72751428-2743-4bda-acf5-4218a4279cd3";
7 const options = {
8 suppressAuth: false
9 };
10
11 return authorization.assignRole(roleId, memberId, options)
12 .then(() => {
13 console.log("Role assigned to member");
14 })
15 .catch((error) => {
16 console.error(error);
17 });
18});