HeadlinesBriefing favicon HeadlinesBriefing.com

Secure Docusaurus with Vercel Middleware

DEV Community •
×

Standard hosting leaves Docusaurus documentation exposed to the public internet. This tutorial outlines a serverless approach using Vercel Edge Middleware to secure your static site. The architecture functions as a two-layer security model: a 'bouncer' at the CDN edge intercepts requests, while serverless functions handle the identity verification and session management.

The solution relies on a stateless JWT strategy. Instead of managing a complex database, the system issues secure cookies via an email OTP flow. This ensures robust protection for all routes without requiring server management. It effectively transforms a static generator into a private hub, maintaining high performance while keeping sensitive content behind a verified login.

Implementation involves configuring `middleware.ts` to intercept traffic before it reaches the origin. The middleware checks for valid authentication cookies and redirects unauthorized users to a login page. This setup leverages Vercel's global network to enforce security rules instantly. It allows teams to host internal documentation efficiently, balancing the speed of static sites with the security of a dynamic application.