Skip to main content
The roles plugin stores code-defined role assignments on users and provides access helpers. It does not add access rules to your collections.

Install

Define roles

When roles are listed, the plugin adds a roles multi-select field to the users auth collection. Assignments are stored as slugs. There is no role-definition collection. Roles are literal strings. No slug is reserved, and no role receives implicit access. admin is a common convention, but it is not a superuser unless your access functions grant it. rolesPlugin() and rolesPlugin({ roles: [] }) are inert and add no field. The plugin runs with order: 100, after other first-party plugins, so it binds allow() clauses on the collections they add wherever you list it.

Apply access

allow(...clauses) composes role, ownership, and function clauses into a FrogBot access function:
Every role must be written where it should apply. For example, allow('finance') denies a user assigned only admin; use allow('admin', 'finance') to grant both. An ownership clause names a relationship field. On create, FrogBot stamps that field when the matching role grants access. On read, update, and delete, it returns an ownership query. Function clauses returning false abstain rather than vetoing another clause. Ownership and Where clauses are for collection access. Boolean role and function clauses also work in field and agent access.

Request helpers

Role field access

The injected roles field uses FrogBot’s default field access. Use rolesFieldAccess when role assignments need different access rules:
The object is passed directly to the injected field.

Default role

By default, new users receive no role. Set defaultRole to configure the injected field’s defaultValue:
The default must be listed in roles. Explicit assignments, including roles: [], are preserved. Existing users are unchanged.

Custom role sources

By default, helpers read req.user.roles. Use resolveRoles when assignments come from another synchronous source, such as JWT claims or tenant membership:
The resolver must return listed slugs. Its result is cached once per request and shared by predicates and allow() clauses.

Bootstrap access

The plugin does not promote the first user. Bootstrap privileged assignments explicitly with FrogBot’s Local API from a seed or migration, with overrideAccess: true:
You can also assign roles when seeding users:
For application-managed onboarding, add a userland collection hook that derives the assignment from your own invite, tenant, or deployment rules. Keep that bootstrap condition in application code and remove or disable one-time logic after it succeeds.

Options

The plugin injects the roles field into the users collection only, and only when that collection has auth enabled; with roles configured and no auth-enabled users collection, it logs a warning at startup. It throws at startup if users already has a field named roles, or if an allow() clause names a role that isn’t listed. RoleSlug is imported from @frogbotai/plugin-roles. frogbot generate:types types it as the union of the configured role slugs, so resolveRoles and hasRole() reject unknown roles. Without generated types it’s string.