Prerequisites
Before installing AuthKit Next.js, make sure you have:- A Next.js 13.5.9+ application using the App Router
- A WorkOS account (sign up for free)
- Node.js 18 or later
Install the package
Install AuthKit Next.js using your preferred package manager:Environment variables
Create or update your.env.local file with the following required variables:
.env.local
Get your WorkOS credentials
Find your Client ID
Navigate to the WorkOS Dashboard and copy your Client ID from the API Keys section.
Get your API Key
In the same section, copy your API Key. Use
sk_test_... for development and sk_live_... for production.Generate a cookie password
The cookie password must be at least 32 characters. Generate a secure password using one of these methods:
Optional configuration
Customize AuthKit behavior with these optional environment variables:| Variable | Default | Description |
|---|---|---|
WORKOS_COOKIE_MAX_AGE | 34560000 (400 days) | Session cookie lifetime in seconds |
WORKOS_COOKIE_DOMAIN | None | Cookie domain (leave empty for current domain only) |
WORKOS_COOKIE_NAME | wos-session | Name of the session cookie |
WORKOS_COOKIE_SAMESITE | lax | SameSite attribute: lax, strict, or none |
WORKOS_API_HOSTNAME | api.workos.com | WorkOS API hostname |
WORKOS_API_HTTPS | true | Use HTTPS for API calls |
WORKOS_API_PORT | None | Custom port for API calls |
Example: Custom cookie settings
.env.local
Logout URI configuration
To use thesignOut() method, set a default Logout URI in your WorkOS dashboard:
Open dashboard settings
Go to the WorkOS Dashboard and navigate to Configuration → Redirects
TypeScript configuration
AuthKit Next.js includes TypeScript definitions out of the box. No additional configuration is needed. If you’re using strict mode, you may want to enable these options intsconfig.json:
tsconfig.json
Verify installation
Confirm the package is installed correctly:Next steps
Quickstart guide
Set up authentication in your Next.js app in under 5 minutes