realtime_check_permission( )


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:

  • If this function isn't defined, all subscribers will receive the default permissions: {"read": true}.
  • In Wix Studio, you don't need to define this function, but you must create a backend file named realtime-permissions.js. Without this file, subscriptions will fail.

Implement permissions logic for channels and subscribers by either:

  • Including all permissions logic in the body of this function.
  • Use the 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.

Method Declaration
Copy
function realtime_check_permission(
  channel: Channel,
  subscriber: Subscriber,
): Promise<ChannelPermissions> | ChannelPermissions;
Method Parameters
channelChannelRequired

The channel, and optionally the resource, to check permissions for.


subscriberSubscriberRequired

The subscriber to check permissions for.

Returns
Return Type:Promise<ChannelPermissions> | ChannelPermissions
JavaScript
// 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; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?