Install
Define roles
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:
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 injectedroles field uses FrogBot’s default field access. Use rolesFieldAccess when role assignments need different access rules:
Default role
By default, new users receive no role. SetdefaultRole to configure the injected field’s defaultValue:
roles. Explicit assignments, including roles: [], are preserved. Existing users are unchanged.
Custom role sources
By default, helpers readreq.user.roles. Use resolveRoles when assignments come from another synchronous source, such as JWT claims or tenant membership:
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, withoverrideAccess: true:
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.