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.
Introduction
Fern allows you to restrict parts of your navigation to individuals with specific roles. RBAC enables you to create different levels of access for different user types within your documentation.
When RBAC is configured, Ask Fern automatically respects these permissions so users only receive answers from content they’re authorized to view.
Use cases
Role-based access control is helpful for scenarios such as:
- Partner documentation: Provide exclusive API documentation to integration partners while keeping internal docs private
- Beta features: Share new features with beta users before general release
- Internal documentation: Restrict sensitive documentation to employees only
- Tiered access: Offer different documentation levels based on subscription tiers
- Customer-specific content: Show different documentation based on customer type or plan
How it works
Every user automatically has the everyone
role, including unauthenticated visitors. Pages marked with the everyone
role are publicly accessible without needing to log in.
If a user visits content that requires authentication (i.e., content not marked as visible to everyone
), Fern checks for an authentication cookie to determine the user’s roles. If the user lacks the required role or isn’t authenticated, Fern redirects them to the login URL you provided during setup.
Set up RBAC
Define all the roles
in your docs.yml
Start by using a roles
key to define all the different roles:
Configure authentication via a fern_token
Fern uses a browser cookie called fern_token
to identify authenticated users and their roles. If this cookie is not present when a user tries to access restricted content, Fern redirects them to your login page.
You can set up this authentication using either JWT or OAuth:
JWT
You are responsible for creating and setting the fern_token
cookie in your authentication system.
Upon login, set a JWT for the user using a secret key that Fern provides. The JWT must include a fern
claim with a roles
array:
OAuth
When a user needs authentication, Fern initiates an OAuth flow and redirects them to your authentication endpoint. You configure your OAuth endpoints to return user role information.
Contact Fern for setup
When you’re ready to implement RBAC, contact support@buildwithfern.com.
Optional
If you’d like restricted pages to be visible but locked to unauthenticated users (rather than completely hidden), notify Fern during this step.Access control within navigation
You can designate viewers on the following navigation items:
products
versions
tabs
sections
pages
api references
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.
Access control within MDX pages
You can restrict specific content within your MDX pages to users with certain roles. This allows you to show different content to different user types on the same page.
Basic usage
Use the <If />
component to conditionally render content based on user roles:
Multiple 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.