> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: add(channel: Channel, handler: PermissionsHandler) # Method package: wixRealtimeBackend # Method menu location: wixRealtimeBackend --> PermissionsRouter --> add # Method Link: https://dev.wix.com/docs/velo/velo-only-apis/wix-realtime-backend/permissions-router/add.md # Method Description: Sets a permissions handler for a specific channel or channel resource. The handler set by the `add()` function is used for permission checks by the permissions router for the channel or channel resource specified in the `channel` property. Adding a handler to a specific channel without a specified resource adds a handler for all permissions checks on the channel and all permissions checks on any of the channel's resources that do not have their own permissions handlers. For example, suppose you have the following channel, resources, and permissions: + channel: A, permissions: handler X is specified using the `add()` function + channel: A, resource: 1, permissions: handler Y is specified using the `add()` function + channel: A, resource: 2, permissions: no handler is specified Permissions will be checked as follows: + A: use handler X + A, 1: use handler Y + A, 2: use handler X # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Set a permissions handler for a specific channel ```javascript // In realtime-permissions.js import {permissionsRouter} from 'wix-realtime-backend'; // ... const adminAnnouncements = {"name": "announcements"} permissionsRouter.add( adminAnnouncements, (channel, subscriber) => { // add permissions check logic and return // permissions for announcements channel if(subscriber.type === "Admin") { return {"read": true}; } else { return {"read": true}; } } ); ``` ## Grant permissions for a channel based on subscriber type using the permissions router ```javascript // In realtime-permissions.js import {permissionsRouter} from 'wix-realtime-backend'; permissionsRouter.default( (channel, subscriber) => { return {"read": true}; } ); const membersOnlyChannel = {"name": "MembersOnly"}; permissionsRouter.add(membersOnlyChannel, (channel, subscriber) => { if(subscriber.type === "Member") { return {"read": true}; } else { return {"read": false}; } }); export function realtime_check_permission(channel, subscriber) { return permissionsRouter.check(channel,subscriber); } ``` ## Grant permissions based on user data using the permissions router ```javascript // In realtime-permissions.js import { members } from `wix-members-backend`; import { permissionsRouter } from 'wix-realtime-backend'; permissionsRouter.default((channel, subscriber) => { return {"read": true}; }); const membersOnlyChannel = {"name": "MembersOnly"}; permissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => { let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] }); if(channel.resourceId === "BobsOnly") { if(member.contactDetails.firstName === "Bob") { return { "read": true }; } else { return { "read": false }; } } else { return { "read": true }; } } ); export function realtime_check_permission(channel, subscriber) { return permissionsRouter.check(channel, subscriber); } ``` ---