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:
If a permissions handler for the specified channel or channel resource exists, it's invoked and its result is returned.
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.
If no handler is found for the specified channel, but a default permissions handler exists, it's invoked and its result is returned.
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:
JavaScript | Copy Codeexport function realtime_check_permission(channel, subscriber) {return permissionsRouter.check(channel,subscriber);}
Syntax
function check(channel: Channel, subscriber: Subscriber): Promise<ChannelPermissions> | ChannelPermissions
check Parameters
NAME
TYPE
DESCRIPTION
Channel to check permissions for.
Subscriber to check permissions for.
Returns
The permissions granted to the subscriber on the channel or channel resource.
Return Type:
|
ChannelPermissionsChannelPermissions
ChannelPermissions
NAME
TYPE
DESCRIPTION
Whether the subscriber has read permissions. Defaults to true
.
Was this helpful?
1// In realtime-permissions.js23import {permissionsRouter} from 'wix-realtime-backend';45// ...67export function realtime_check_permission(channel, subscriber) {8 return permissionsRouter.check(channel,subscriber);9}
1// In realtime-permissions.js23import {permissionsRouter} from 'wix-realtime-backend';45permissionsRouter.default( (channel, subscriber) => {6 return {"read": true};7} );89const membersOnlyChannel = {"name": "MembersOnly"};1011permissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {12 if(subscriber.type === "Member") {13 return {"read": true};14 }15 else {16 return {"read": false};17 }18});1920export function realtime_check_permission(channel, subscriber) {21 return permissionsRouter.check(channel,subscriber);22}
1// In realtime-permissions.js23import { members } from `wix-members-backend`;4import { permissionsRouter } from 'wix-realtime-backend';56permissionsRouter.default((channel, subscriber) => {7 return {"read": true};8});910const membersOnlyChannel = {"name": "MembersOnly"};1112permissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {13 let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });1415 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} );2728export function realtime_check_permission(channel, subscriber) {29 return permissionsRouter.check(channel, subscriber);30}