Access ControlBeta
Protect your documentation pages with authentication. Control who can see what — from simple password protection to full OAuth with role-based access.
Overview
xyd access control provides:
- Page-level protection — mark pages as public or protected via frontmatter or pattern rules
- Group-based access — restrict pages to specific roles (admin, premium, etc.)
- SSR exclusion — protected content never appears in HTML source
- Edge middleware — server-side protection for Netlify, Vercel, Cloudflare, or standalone Node.js
- Search filtering — protected pages excluded from search for unauthorized users
- Sidebar filtering — protected nav items hidden from unauthorized users
Quick Start
Add accessControl to your docs.json:
Auth Providers
JWT
External login server signs a JWT and redirects back to your docs with the token.
OAuth 2.0
Redirect to an OAuth provider (Auth0, Google, GitHub, etc.) for authentication.
Password
Simple shared-password protection with an external password form.
Page-Level Access
Frontmatter
Override access on individual pages:
| Field | Effect |
|---|---|
public: true | Always public, even if defaultAccess is "protected" |
public: false | Always protected, even if defaultAccess is "public" |
accessGroups: ["admin"] | Requires membership in at least one listed group |
Pattern Rules
Match pages by glob pattern in docs.json:
Rules are evaluated in order — first match wins.
Evaluation Priority
- Frontmatter (highest) —
public/accessGroupsin page metadata - Pattern rules —
rulesarray indocs.json - Default access (lowest) —
defaultAccess: "public" | "protected"
Edge Middleware
For production deployments, enable server-side protection:
| Platform | Description |
|---|---|
"node-edge" | Standalone Node.js server (auto-generated by xyd build) |
"netlify-edge" | Netlify Edge Functions |
"vercel-edge" | Vercel Routing Middleware |
"cloudflare-edge" | Cloudflare Pages Functions |
Node.js Server
With deploy.platform: "node-edge", xyd build generates a server.mjs in your build output:
The server:
- Verifies JWT signatures (HS256)
- Checks access rules on every request
- Returns 302 redirect for unauthorized users (even for
curl) - Protects content chunks from direct access
Environment Variables
| Variable | Required | Description |
|---|---|---|
AUTH_SECRET | Yes (for JWT) | JWT signing secret (≥32 characters) |
PORT | No | Server port (default: 3000) |
Session Configuration
Login Page
xyd provides a built-in login page at /login. Customize it:
Security Model
| Layer | Protection | Platform |
|---|---|---|
Layer 1 (default) | SSR exclusion + client-side auth. Content not in HTML source. | Any static host |
Layer 2 (deploy) | Server-side JWT verification. Content never served to unauthorized. | Node.js, Netlify, Vercel, Cloudflare |
CLI Commands
| Command | Description |
|---|---|
xyd build | Builds static site. With deploy.platform: "node-edge", generates server.mjs. |
xyd serve | Serves the built site in production. Auto-detects deploy mode. |
xyd dev | Development server with access control middleware. |
Examples
Show your support! Star us on GitHub ⭐️