Checks permissions for a subscriber on a channel or channel resource.
The realtime_check_permission
hook is triggered when a site visitor subscribes
to a channel to check what permissions the subscriber will have.
The realtime_check_permission()
function is not a function that you call from
your code. You define the function in a file named realtime-permissions.js
in your site's Backend section.
Important:
{"read": true}
.Implement permissions logic for channels and subscribers by either:
PermissionsRouter
to add permissions
logic per channel. Then call check()
in the body of
this function and return the permissions object it returns.Note: When previewing your site, permissions for read are always granted.
function realtime_check_permission(
channel: Channel,
subscriber: Subscriber,
): Promise<ChannelPermissions> | ChannelPermissions;
The channel, and optionally the resource, to check permissions for.
The subscriber to check permissions for.
// In realtime-permissions.js
export function realtime_check_permission(channel, subscriber) {
// set default permissions
let permissions = { read: true };
if (channel.name === "MembersOnly") {
if (subscriber.type === "Member") {
permissions.read = true;
} else {
permissions.read = false;
}
}
return permissions;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.