Search.../

assignRole( )

Assigns a role to group members.

Description


Note: This function is only relevant for site admins, and group members with group admin permissions.

The assignRole() function returns a Promise that resolves to the newly-assigned role after it has successfully been assigned. Assigning a role overrides an existing role. For example, assigning a member role to an admin unassigns their admin role.

Syntax

function assignRole(identifiers: Identifiers, role: string, [options: Options]): Promise<Role>

assignRole Parameters

NAME
TYPE
DESCRIPTION
identifiers
Identifiers

Group ID and member IDs.

role
string

Group member role to assign. One of:

  • "MEMBER": Group member.
  • "ADMIN": Group admin.
options
Optional
Options

Authorization options.

Returns

Return Type:

Promise<Role>
NAME
TYPE
DESCRIPTION
role
string

Group member role. One of:

  • "MEMBER": Group member.
  • "ADMIN": Group admin.

Was this helpful?

Assign a role to a group member

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { roles } from 'wix-groups-backend';
3
4// Sample identifiers value:
5// {
6// memberIds: ['7fe8e9e1-d050-4c86-9684-e7f231600a34'],
7// groupId: '0261a737-2361-4468-a3b1-5ec2b0667836.'
8// }
9//
10// Sample role value:
11// 'ADMIN'
12//
13// Sample options value:
14// {
15// suppressAuth: true
16// }
17
18
19export const assignRole = webMethod(Permissions.Anyone, (identifiers, role, options) => {
20 return roles.assignRole(identifiers, role, options)
21 .then((response) => {
22 console.log(response);
23 })
24 .catch((error) => {
25 console.error(error);
26 });
27});
28
29/* Promise resolves to:
30 * role: "ADMIN"
31 */