> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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: check(channel: Channel, subscriber: Subscriber)

# Method package: wixRealtimeBackend

# Method menu location: wixRealtimeBackend --> PermissionsRouter --> check

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/wix-realtime-backend/permissions-router/check.md

# Method Description:

Checks the permissions for a subscriber on a channel or channel resource.

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:

 1. If a permissions handler for the specified channel or channel resource exists,
    it's invoked and its result is returned.
 1. 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.
 1. If no handler is found for the specified channel, but a default permissions handler
    exists, it's invoked and its result is returned.
 1. 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()`](#realtime_check_permission) function like so:

 ```JavaScript
 export function realtime_check_permission(channel, subscriber) {
   return permissionsRouter.check(channel,subscriber);
 }
 ```



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Check permission for a subscriber to a channel

```javascript
// In realtime-permissions.js

import {permissionsRouter} from 'wix-realtime-backend';

// ...

export function realtime_check_permission(channel, subscriber) {
  return permissionsRouter.check(channel,subscriber);
}
```

## 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);
}
```

---