> 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: default(handler: PermissionsHandler) # Method package: wixRealtimeBackend # Method menu location: wixRealtimeBackend --> PermissionsRouter --> default # Method Link: https://dev.wix.com/docs/velo/velo-only-apis/wix-realtime-backend/permissions-router/default.md # Method Description: Sets a permissions handler for default permissions. The handler set by the `default()` function is used for permission checks by the permissions router for all channels where an explicit handler has not been added. For channel resources, if no explicit handler has been set, the resource will inherit the permissions of its parent channel. For example, suppose you have the following channel, resources, and permissions: + channel: A, permissions: no handler specified + channel: A, resource: 1, permissions: no handler specified + channel: A, resource: 2, permissions: handler is specified Permissions will be checked as follows: + A: use the handler set by `default()` function + A, 1: use the handler set by `default()` function + A, 2: use the handler set by `add()` function for this resource If no default handler is set, subscribers to channels without explicit permissions handlers will receive the following permissions: `{"read": true}` # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Set a default permissions handler ```javascript // In realtime-permissions.js import {permissionsRouter} from 'wix-realtime-backend'; // ... permissionsRouter.default( (channel, subscriber) => { // return default permissions 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); } ``` ---