auth-js
БесплатноБез исполняемых скриптовНе проверенProduction-ready Auth.js v5 setup for Next.js and Cloudflare Workers. Use when: setting up authentication, implementing OAuth/credentials/magic links…
Об этом скилле
Auth.js v5 Authentication Stack
Production-tested: Multiple Next.js and Cloudflare Workers projects Last Updated: 2025-10-26 Status: Production Ready ✅ Official Docs: https://authjs.dev
⚠️ BEFORE YOU START (READ THIS!)
CRITICAL FOR AI AGENTS: If you're Claude Code helping a user set up Auth.js:
- Explicitly state you're using this skill at the start of the conversation
- Reference patterns from the skill rather than general knowledge
- Prevent known issues listed in
references/common-errors.md - Don't guess - if unsure, check the skill documentation
USER ACTION REQUIRED: Tell Claude to check this skill first!
Say: "I'm setting up Auth.js - check the auth-js skill first"
Why This Matters (Real-World Results)
Without skill activation:
- ❌ Setup time: ~15 minutes
- ❌ Errors encountered: 3-5 (AUTH_SECRET, CallbackRouteError, edge issues)
- ❌ Manual fixes needed: 3-4 commits
- ❌ Token usage: ~15k
- ❌ User confidence: Multiple debugging sessions
With skill activation:
- ✅ Setup time: ~3 minutes
- ✅ Errors encountered: 0
- ✅ Manual fixes needed: 0
- ✅ Token usage: ~6k (60% reduction)
- ✅ User confidence: Instant success
Known Issues This Skill Prevents
- Missing AUTH_SECRET → JWEDecryptionFailed error
- CallbackRouteError → Throwing in authorize() instead of returning null
- Route not found → Incorrect file path for [...nextauth].js
- Edge incompatibility → Using database session without edge-compatible adapter
- PKCE errors → OAuth provider misconfiguration
- Session not updating → Missing middleware
- v5 migration issues → Namespace changes, JWT salt changes
- D1 binding errors → Wrangler configuration mismatch
- Credentials with database → Incompatible session strategy
- Production deployment failures → Missing environment variables
- Token refresh errors → Incorrect callback implementation
- JSON expected but HTML received → Rewrites configuration in Next.js 15
All of these are handled automatically when the skill is active.
Table of Contents
- Quick Start - Next.js
- Quick Start - Cloudflare Workers
- Core Concepts
- Session Strategies
- Provider Setup
- Database Adapters
- Middleware Patterns
- Advanced Features
- Critical Rules
- Common Errors & Fixes
- Templates Reference
Quick Start: Next.js
Prerequisites
# Next.js 15+ with App Router
npm create next-app@latest my-app
cd my-app
Installation
npm install next-auth@latest
npm install @auth/core@latest
# Choose your database adapter (if using database sessions)
npm install @auth/prisma-adapter # For PostgreSQL/MySQL
npm install @auth/d1-adapter # For Cloudflare D1
1. Create Auth Configuration
Option A: Simple Setup (JWT sessions, no database)
// auth.ts
import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
],
})
Option B: Edge-Compatible Setup (recommended for middleware)
// auth.config.ts (edge-compatible, no database)
import type { NextAuthConfig } from "next-auth"
import GitHub from "next-auth/providers/github"
export default {
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
],
} satisfies NextAuthConfig
// auth.ts (full config with database)
import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
import authConfig from "./auth.config"
const prisma = new PrismaClient()
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" }, // CRITICAL: Force JWT for edge compatibility
...authConfig,
})
2. Create API Route Handler
// app/api/auth/[...nextauth]/route.ts
import { handlers } from "@/auth"
export const { GET, POST } = handlers
3. Add Middleware (Optional but Recommended)
// middleware.ts
export { auth as middleware } from "@/auth"
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
}
4. Environment Variables
# .env.local
AUTH_SECRET=your-secret-here # Generate with: npx auth secret
AUTH_GITHUB_ID=your_github_client_id
AUTH_GITHUB_SECRET=your_github_client_secret
# CRITICAL: In production, AUTH_SECRET is REQUIRED
5. Use in Components
**Server Component (
Установить auth-js в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл auth-js?
Production-ready Auth.js v5 setup for Next.js and Cloudflare Workers. Use when: setting up authentication, implementing OAuth/credentials/magic links, configuring D1 or PostgreSQL adapters, debugging session issues, migrating from v4 to v5, fixing edge compatibility, troubleshooting JWT/database sessions, resolving AUTH_SECRET errors, fixing CallbackRouteError, or implementing RBAC. Covers: Next.js App Router & Pages Router, Cloudflare Workers + D1, OAuth providers (GitHub, Google, etc.), credentials auth, magic links, JWT vs database sessions, middleware patterns, role-based access control, token refresh, edge runtime compatibility, and common error prevention. Keywords: Auth.js, NextAuth.js, authentication, OAuth, credentials, magic links, D1 adapter, Cloudflare Workers, Next.js middleware, JWT session, database session, refresh tokens, RBAC, edge compatibility, AUTH_SECRET, CallbackRouteError, CredentialsSignin, JWEDecryptionFailed, session not updating, route protection
Как установить скилл auth-js?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл auth-js запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic