AuthkitMiddlewareOptions type configures the authkitMiddleware function that manages authentication for your Next.js application.
Type definition
Properties
Enables debug logging for authentication operations. When
true, logs session refresh attempts, authentication failures, and other diagnostic information to the console.Useful for troubleshooting authentication issues during development.Configuration for automatic authentication enforcement. When enabled, unauthenticated users are automatically redirected to the sign-in page, except for paths in the
unauthenticatedPaths allowlist.See AuthkitMiddlewareAuth below.The callback URL where WorkOS will redirect users after authentication. Must match the redirect URI configured in your WorkOS dashboard.If not provided, falls back to the
WORKOS_REDIRECT_URI environment variable.Array of path patterns that should show the sign-up screen instead of sign-in. Supports glob patterns.Examples:
["/signup", "/register", "/join/*"]When
true, sets the access token as a client-side cookie on initial page loads, enabling client components to access authentication state without additional API calls.Only applies to document requests (initial page loads), not API or RSC requests.AuthkitMiddlewareAuth
Configuration for automatic authentication enforcement:Whether to enable automatic authentication enforcement. When
true, all requests require authentication except those matching paths in unauthenticatedPaths.Array of path patterns that don’t require authentication. Supports glob patterns using path-to-regexp syntax.The callback redirect URI is automatically added to this list to prevent redirect loops.
Usage
Basic middleware
With middleware auth enabled
With sign-up paths
With eager auth for client components
With debug mode
Path pattern matching
TheunauthenticatedPaths and signUpPaths arrays support glob patterns using path-to-regexp syntax:
/about- Exact match/blog/*- Matches/blog/and/blog/post-1/api/:endpoint- Matches/api/users,/api/posts, etc./docs/**- Matches/docs/guide/introand any nested path
Related functions
authkitMiddleware()- Creates the middleware function (see source at ~/workspace/source/src/middleware.ts:6)authkit()- Alternative API for manual session management