Search.../

check( )

Checks the permissions for a subscriber on a channel or channel resource.

Description

The check() function returns a Promise that resolves to the permissions for the specified user on the specified channel or channel resource.

The check is performed as follows:

  1. If a permissions handler for the specified channel or channel resource exists, it's invoked and its result is returned.

  2. If no handler is found for the specified channel resource, but a handler exists for the resource's channel, it's invoked and its result is returned.

  3. If no handler is found for the specified channel, but a default permissions handler exists, it's invoked and its result is returned.

  4. If the default handler has not been found, the default permissions are returned.

    The default permissions are: {"read": true}

This function is typically called in the body of the realtime_check_permission() function like so:

export function realtime_check_permission(channel, subscriber) {
return permissionsRouter.check(channel,subscriber);
}
JavaScript | Copy Code

Authorization

Request

This endpoint does not take any parameters

Response Object

The permissions granted to the subscriber on the channel or channel resource.

NAME
TYPE
DESCRIPTION
read
boolean

Whether the subscriber has read permissions. Defaults to true.

Status/Error Codes

Was this helpful?

Check permission for a subscriber to a channel

Copy Code
1// In realtime-permissions.js
2
3import {permissionsRouter} from 'wix-realtime-backend';
4
5// ...
6
7export function realtime_check_permission(channel, subscriber) {
8 return permissionsRouter.check(channel,subscriber);
9}
Grant permissions for a channel based on subscriber type using the permissions router

Copy Code
1// In realtime-permissions.js
2
3import {permissionsRouter} from 'wix-realtime-backend';
4
5permissionsRouter.default( (channel, subscriber) => {
6 return {"read": true};
7} );
8
9const membersOnlyChannel = {"name": "MembersOnly"};
10
11permissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {
12 if(subscriber.type === "Member") {
13 return {"read": true};
14 }
15 else {
16 return {"read": false};
17 }
18});
19
20export function realtime_check_permission(channel, subscriber) {
21 return permissionsRouter.check(channel,subscriber);
22}
Grant permissions based on user data using the permissions router

Copy Code
1// In realtime-permissions.js
2
3import { members } from `wix-members-backend`;
4import { permissionsRouter } from 'wix-realtime-backend';
5
6permissionsRouter.default((channel, subscriber) => {
7 return {"read": true};
8});
9
10const membersOnlyChannel = {"name": "MembersOnly"};
11
12permissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {
13 let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });
14
15 if(channel.resourceId === "BobsOnly") {
16 if(member.contactDetails.firstName === "Bob") {
17 return { "read": true };
18 }
19 else {
20 return { "read": false };
21 }
22 }
23 else {
24 return { "read": true };
25 }
26} );
27
28export function realtime_check_permission(channel, subscriber) {
29 return permissionsRouter.check(channel, subscriber);
30}