Role-based access control
Pro and Enterprise feature
This feature is available only for the Pro and Enterprise plans. To get started, reach out to support@buildwithfern.com.
RBAC is a feature of JWT and OAuth authentication. Once a user logs in through either method, Fern checks the fern_token cookie to determine their roles and controls access to pages, sections, and other navigation items accordingly.
RBAC is useful for partner docs, beta features, tiered access, and internal content. You can combine it with API key injection in a single token. When RBAC is configured, Ask Fern automatically respects these permissions.
Setup
To enable RBAC, follow the JWT or OAuth setup guide, then define your roles in docs.yml:
Every user automatically has the everyone role, including unauthenticated visitors. If a user lacks the required role or isn’t authenticated, Fern redirects them to your login page.
Restricting content
Once RBAC is configured, use viewers in your navigation and the <If /> component in your pages to control what each role can see.
In navigation
You can assign viewers to the following navigation items: products, versions, tabs, sections, pages, api references, and changelogs.
If you don’t specify viewers, the content will be visible to any authenticated user. To make content publicly accessible, explicitly set viewers to everyone.
Viewership is inherited. For example, if a section can only be viewed by admins, then all its pages and nested sections can also only be viewed by admins.
In MDX pages
Use the <If /> component to conditionally render content based on user roles:
You can specify multiple roles. Content will be visible to users who have any of the specified roles:
The <If> component respects the same role inheritance rules as navigation items. If a user has access to a page, they can see all content on that page that matches their roles.