This library is designed specifically for the Next.js App Router. For Pages Router support, refer to the WorkOS Node SDK.
What you’ll build
AuthKit Next.js gives you everything you need to add enterprise-ready authentication to your Next.js application:Secure authentication
Enterprise SSO, social login, and email/password authentication out of the box
Session management
Automatic token refresh and secure cookie-based sessions with zero configuration
Server & client hooks
Access user data in both server and client components with
withAuth() and useAuth()Advanced features
User impersonation, feature flags, organization switching, and API key validation
Quick links
Installation
Install the package and configure your environment variables
Quickstart
Get authentication working in under 5 minutes
API reference
Explore all available methods and components
GitHub
View source code and contribute to the project
Key features
Built for Next.js App Router
Designed from the ground up for Next.js 13+ with full support for:- Server Components and Server Actions
- React Server Components (RSC)
- Next.js 16+ proxy and middleware patterns
- Streaming and concurrent rendering
Enterprise-ready authentication
Powered by WorkOS AuthKit, you get:- Single Sign-On (SSO) with major providers
- Social authentication (Google, GitHub, Microsoft)
- Magic link and email/password authentication
- Multi-factor authentication (MFA)
- User impersonation for support scenarios
Simple developer experience
Flexible middleware
Protect routes with a simple matcher configuration:Use cases
B2B SaaS applications
B2B SaaS applications
AuthKit Next.js is perfect for B2B applications that need enterprise SSO, organization management, and user impersonation for customer support.
Internal tools and dashboards
Internal tools and dashboards
Quickly add authentication to internal tools with support for your company’s existing SSO providers.
Multi-tenant applications
Multi-tenant applications
Built-in support for organization switching and session management across multiple tenants.
API services
API services
Includes
validateApiKey() for securing public API endpoints with WorkOS API keys.Architecture
AuthKit Next.js follows a middleware-first architecture:- Middleware layer - Handles session refresh and authentication checks before requests reach your pages
- Callback route - Processes OAuth callbacks from WorkOS AuthKit
- Server helpers - Access session data in Server Components with
withAuth() - Client hooks - Access session data in Client Components with
useAuth() - Secure storage - Encrypted session cookies using iron-session
Browser and Next.js support
AuthKit Next.js supports:- Next.js 13.5.9+ (App Router required)
- Next.js 14, 15, and 16
- React 18 and 19
- All modern browsers (Chrome, Firefox, Safari, Edge)
Next steps
Install the package
Follow the installation guide to add AuthKit to your Next.js project
Complete the quickstart
Get authentication working in under 5 minutes with the quickstart guide