NextAuth.js / Auth.js
CommunitySecure Next.js auth with safe structure
System Documentation
What problem does it solve?
Authentication setups in Next.js apps easily become inconsistent and unsafe when route handlers, session configuration, and role checks are scattered across the codebase. Architecting NextAuth correctly prevents broken sign-in/CSRF flows, avoids mismatched session strategies, and ensures protected routes reliably enforce authorization across both server and client.
Core Features & Use Cases
- Centralized auth configuration: Keep providers, callbacks, adapter wiring, JWT/database session strategy, and custom session field mapping in a single exported authOptions file.
- Correct NextAuth route handling: Use the catch-all NextAuth route handler directory and export both GET and POST handlers so OAuth callbacks and CSRF protection work end-to-end.
- Consistent session access and protection: Use getServerSession for Server Components and routes, useSession for Client Components, and protect routes via NextAuth middleware with an appropriate matcher and role-based authorized callback.
Quick Start
Ask your coding agent to implement a NextAuth.js/Auth.js setup using app/api/auth/[...nextauth]/route.ts with GET and POST exports, a single src/lib/auth.ts authOptions export, and middleware protection for protected routes while using getServerSession on the server and useSession in client components.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: NextAuth.js / Auth.js Download link: https://github.com/Levironexe/architect/archive/main.zip#nextauth-js-auth-js Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.