bolkAuthMiddleware runs before matched Next.js routes render. It checks the session cookie and redirects anonymous users to the sign-in page.
Basic Setup
Options
| Option | Type | Default | Description |
|---|---|---|---|
signInUrl | string | "/sign-in" | Redirect destination when no valid session exists. |
onboardingUrl | string | "/onboarding" | Redirect destination for onboarding checks. |
publicRoutes | string[] | [] | Routes that bypass auth. Exact routes also match subpaths. |
ignoredRoutes | string[] | [] | Reserved option for compatibility. |
afterSignInUrl | string | Not used by middleware redirects | Reserved option for compatibility. |
Public Routes
Always include the auth API route and your sign-in/sign-up pages:
Routes containing *, (.*), or regex-like tokens are treated as patterns.
What Middleware Checks
- If the path is public, continue immediately.
- Read the session cookie.
- Verify the JWT signature with
auth.config.secret. - Redirect to
signInUrlwhen the cookie is missing or invalid. - Continue when the session is valid.
Middleware performs a lightweight JWT check and does not fetch the user from the database. Use requireAuth() in pages or actions when you need the user record.