Showing private content to signed-in visitors on a public docs site
Show public documentation to everyone and private content to signed-in visitors.
Keep your docs site public. Adaptive content uses visitor claims to show extra content to signed-in visitors.
Configure authenticated access, define visitor claims, and apply conditions to private content.
Enabling adaptive content
In your docs site, go to Settings → Audience.
Under Access, select Public.
Under Access, select Click to enable adaptive content.
Configuring authenticated access
If you use a supported provider, install its integration:
In your docs site, go to Settings → Integrations.
Install the integration for your provider.
Follow your provider’s setup guide.
Choose your provider’s setup guide:
If you use your own authentication service, see Using your own login page.
Using your own login page
Set up your login page with Hosting your own login page. It covers the sign-in flow, the private key, and the login URL.
To use the claims from this guide, include them in the token your backend signs. This login handler sends the isCustomer claim from the visitor schema below, and returns the visitor to the page they started from:
Defining your visitor schema
Add each claim that your provider sends to the visitor schema:
In your docs site, go to Settings → Audience.
Under Visitor schema, add a property for each claim.
Set each property’s type.
Click Save.
Use boolean for true or false values. Use string with an enum for a fixed set of values.
For example, this schema expects a claim that identifies a customer:
Adding conditions to private content
Open the condition editor for the content you want to keep private:
For a section, go to Settings → Structure. In the section actions menu, click Add condition.
For a page, in the page actions menu, click Add condition.
For part of a page, use the inline palette to add a Conditional content block. Click the condition badge on the block.
Then apply the condition:
Enter a condition that uses visitor claims, such as
visitor.claims.isCustomer == true.Click Save.
GitBook shows conditional content only when a signed-in visitor’s claims match the condition. All other content remains public.
Adding sign-in and sign-out links
The sign-in and sign-out endpoints are:
Sign in:
https://<your-docs-site-url>/~gitbook/auth/login.Sign out:
https://<your-docs-site-url>/~gitbook/auth/logout.
Add these links to your site header:
In the sidebar, open your docs site and select Layout.
Under the header settings, add a header link.
Enter
Sign inas the link name.Enter the sign-in endpoint as the link URL.
Add a second header link.
Enter
Sign outas the link name.Enter the sign-out endpoint as the link URL.
Select a text link, primary button, or secondary button for each link.
Click Save.
Testing the sign-in flow
Open your docs site in a private browser window. Check that public content shows and private content doesn’t.
Click Sign in and sign in as a visitor whose claims match your conditions.
Check that you return to the page you started from and that the private content now shows.
Click Sign out and check that the private content is hidden again.
Last updated
Was this helpful?