---
name: "next-auth-v5-authjs-providers"
description: "Authenticate users via OAuth, magic email links, and credentials with NextAuth v5 / Auth.js."
metadata:
  author: "Auth.js"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "setup next-auth v5 auth.ts"
  - "authjs edge middleware"
  - "custom session callback nextauth"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Auth.js (NextAuth v5) Edge-Compatible Authentication

Configures Auth.js / NextAuth v5: auth.ts configuration, OAuth providers (Google, GitHub, Discord), database adapters (@auth/prisma-adapter), Edge middleware protection with auth(), and session callbacks.

## When to Invoke
Invoke this skill whenever you need to:
- setup next-auth v5 auth.ts
- authjs edge middleware
- custom session callback nextauth

## Execution SOP & Rules
1. Create auth.ts: export const { handlers, signIn, signOut, auth } = NextAuth({ providers: [...], adapter: ... }).
2. Create route handler: export const { GET, POST } = handlers in app/api/auth/[...nextauth]/route.ts.
3. Access session in Server Components: const session = await auth();.
4. Configure callbacks.session: ({ session, token }) => ({ ...session, user: { ...session.user, id: token.sub } }).

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
