Based on Auth0's and Anthropic's official docs, checked
How to add Auth0 authentication with Claude Code
Auth0 scores 4/5 on our Claude Code fit scale: it ships an official Anthropic-marketplace plugin with 1 skill and no bundled MCP server. Auth0 runs your login page, signup, and MFA for you, so you never store passwords. The Next.js SDK v4 wires it into your app with a proxy file and a handful of env vars. This guide adds login, logout, and a protected route, then shows you how to fix the two errors everyone hits first.
1. Create an Auth0 account and a Regular Web Application
Create an Auth0 account, then open the Dashboard and go to Applications, then Applications, then Create Application. Choose Create it manually, give the application a descriptive name, and pick Regular Web Application as the type. Regular Web Applications are traditional web apps that run most of their logic on the server, which is what the Next.js SDK expects. Select Create, then open the application Settings and copy the Domain, Client ID, and Client Secret. The client secret must stay confidential at all times.
Dashboard > Applications > Applications > Create Application Type: Regular Web ApplicationSource: https://auth0.com/docs/get-started/auth0-overview/create-applications
2. Set the callback and logout URLs
Auth0 only redirects to URLs you have allow-listed, so set them before you test anything. In the same application Settings, set Allowed Callback URLs to http://localhost:3000/auth/callback and Allowed Logout URLs to http://localhost:3000, then save. The callback URL matches the route the Next.js SDK v4 mounts for handling the login response. When you deploy, add your production URLs to both lists and update APP_BASE_URL to match.
Allowed Callback URLs: http://localhost:3000/auth/callback Allowed Logout URLs: http://localhost:30003. Install the official Auth0 plugin
Auth0 agent skills are structured instructions that help AI coding assistants implement Auth0 correctly. Install once, then ask your assistant to add login, protect routes, secure APIs, or set up MFA, and it handles the rest. Auth0 is on the official Claude Code plugins marketplace, so install it from inside Claude Code. For other agents, the Skills CLI installs the same skill files.
/plugin install auth0@claude-plugins-officialnpx skills add auth0/agent-skills --skill auth04. Install the SDK and set your env vars
Install the Auth0 Next.js SDK, then create a .env.local file in your project root with the five values below. The Domain, Client ID, and Client Secret come from the application Settings you opened in step 1. APP_BASE_URL is the URL your app runs on, which is http://localhost:3000 while you develop. AUTH0_SECRET encrypts the session and transaction cookies, and it must be exactly 32 bytes, which is 64 hexadecimal characters. Generate it with openssl, do not invent it by hand, and never commit .env.local to git.
npm install @auth0/nextjs-auth0openssl rand -hex 32AUTH0_DOMAIN=your-tenant.auth0.com AUTH0_CLIENT_ID=your-client-id AUTH0_CLIENT_SECRET=your-client-secret AUTH0_SECRET=paste-the-openssl-output-here APP_BASE_URL=http://localhost:30005. Add the client and the proxy
The SDK v4 setup has two files. First, create the client in lib/auth0.ts. The Auth0Client reads your environment variables automatically, so the file is short. Second, add src/proxy.ts, which is required in v4 because all authentication functionality goes through the proxy. The proxy auto-mounts the auth routes, so you do not need dynamic route handlers: /auth/login starts login, /auth/logout ends the session, /auth/callback handles the response from Auth0, and /auth/profile returns the user profile.
import { Auth0Client } from '@auth0/nextjs-auth0/server'; export const auth0 = new Auth0Client();import { auth0 } from "./lib/auth0"; export default auth0.middleware();6. Add login and logout, then protect a route
Add a login link and a logout link to your layout. Use plain anchor tags that point at the auth routes, not buttons with onClick handlers, because v4 navigation must use anchor tags. For client-side session state, use the useUser hook the SDK provides. For server-side checks, read the session in your page or layout and redirect signed-out visitors to login. Protect API routes with withApiAuthRequired, which rejects requests without a valid session before your handler runs.
<a href="/auth/login">Log in</a> <a href="/auth/logout">Log out</a>import { useUser } from '@auth0/nextjs-auth0/client'; const { user, isLoading } = useUser();7. Run it and fix the two common errors
Start the dev server, open http://localhost:3000, and click Log in. Auth0's Universal Login page opens, you sign in, and Auth0 sends you back to /auth/callback with a session. Two errors catch almost everyone. A JWEDecryptionFailed error means your AUTH0_SECRET is invalid or an old session cookie was encrypted with a different secret. Generate a new secret with openssl, update .env.local, clear your browser cookies for localhost:3000, and restart the dev server. A 404 on /auth/login means the proxy is missing or in the wrong place: check that src/proxy.ts exists, that it matches step 5, and restart the server.
npm run dev
What the Auth0 skill covers
The auth0 skill handles authentication setup, API protection, migration, CLI tooling, and advanced features. It detects your framework and sets up Auth0 with the right SDK, so the same prompt works whether you are on Next.js, React, Express, or Flask. For Next.js it knows the v4 patterns: the proxy file, the /auth/* routes, middleware, and server components.
Beyond the first login, the skill covers MFA with TOTP, SMS, email, push, and WebAuthn, migration from Firebase, Cognito, Supabase, Clerk, or custom auth, and JWT validation with scope checks for Express, Fastify, FastAPI, Spring Boot, ASP.NET Core, and Go APIs. It also handles the Auth0 CLI, so you can ask it to create an application, manage users and roles, or set up a custom domain without opening the Dashboard.
Universal Login, not a form you build
Auth0 hosts the login page your users see, which is called Universal Login. Your app redirects there and Auth0 sends the user back with a session, so your code never sees a password. Social login and MFA are configured in the Auth0 Dashboard, not in your code, and you can brand the login screen to match your design system with the skill's screen generator. That split is the point of the service: the risky parts live with Auth0, and your app only deals with sessions and tokens.
Keep that split clean. Do not build a second login form that posts passwords to your own server, and do not store the client secret anywhere the browser can read it. The secret belongs in .env.local and in your hosting platform's environment settings, alongside AUTH0_SECRET.
Protecting API routes and backends
Pages are only half the job. API routes need the same protection, and the SDK gives you withApiAuthRequired to wrap them. For a third-party backend such as Supabase or Firebase, get the access token on the server and pass it to the backend client, and make sure you pass the accessToken, not the idToken. The backend then verifies the token with your Auth0 domain and audience, which you set as AUTH0_AUDIENCE when you use an Auth0 API. If a backend call returns null for the user identity, check the token format, the audience, and the domain first.
Tips
- Set the callback and logout URLs before your first test login. A wrong URL is the most common reason the flow dies at the redirect.
- Generate AUTH0_SECRET with openssl rand -hex 32. A short or guessable secret breaks session encryption and triggers JWEDecryptionFailed.
- Use anchor tags for login and logout links in SDK v4. Buttons with onClick handlers do not hit the auto-mounted routes the same way.
- Restart the dev server after creating src/proxy.ts. The proxy only takes effect on a fresh start.
- Keep one application per environment. A separate Auth0 application for production keeps test callbacks and secrets away from live users.
Then just ask
Example prompt (our suggestion, not from vendor docs):
"Help me add Auth0 authentication in this project. Follow the Auth0 skills, keep secrets in environment variables, and show me the plan before changing files."
Next steps
How to add Clerk authentication with Claude Code
How to add a Supabase database with Claude Code
How to add Stripe payments with Claude Code
How to deploy to Vercel with Claude Code
How to add an MCP server: Claude Code, Codex, Cursor, Copilot and Antigravity
How to install Claude Code on macOS, Linux and Windows
Frequently asked questions
Auth0 stores the identity: email, name, and login methods. Keep your own profile rows for app-specific data, keyed by the Auth0 user ID, and look them up after the session check.
Sources
- https://auth0.com/docs/quickstart/webapp/nextjs · checked 2026-11-15
- https://auth0.com/docs/quickstart/agent-skills · checked 2026-11-15
- https://auth0.com/docs/get-started/auth0-overview/create-applications · checked 2026-11-15
- https://auth0.com/blog/auth0-agent-skills-ai-coding-assistants/ · checked 2026-11-15
- https://code.claude.com/docs/en/mcp · checked 2026-11-15