# auth > Auth.js v5 setup — providers (GitHub, Google, Credentials), session handling, protected routes, middleware guards, Prisma adapter - Author: Edison - Repository: soilmass/vibe-coding-plugin - Version: 20260130203730 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/soilmass/vibe-coding-plugin - Web: https://mule.run/skillshub/@@soilmass/vibe-coding-plugin~auth:20260130203730 --- --- name: auth description: > Auth.js v5 setup — providers (GitHub, Google, Credentials), session handling, protected routes, middleware guards, Prisma adapter disable-model-invocation: true allowed-tools: Read, Grep, Glob, Bash(npm install *) --- # Auth ## Purpose Auth.js v5 authentication setup for Next.js 15. Covers provider configuration, session access, route protection, and Prisma adapter. The ONE skill for authentication. ## Project State - Has Auth.js: !`[ -f "src/lib/auth.ts" ] && echo "yes" || echo "no"` - Has Prisma adapter: !`grep -q "@auth/prisma-adapter" package.json 2>/dev/null && echo "yes" || echo "no"` ## When to Use - Adding authentication to a Next.js project - Configuring OAuth providers (GitHub, Google) - Protecting routes with middleware - Accessing session data in Server Components ## When NOT to Use - Authorization logic (role checks) → `security` - Login/signup form UI → `react-forms` - API route auth headers → `api-routes` ## Pattern ### Auth.js configuration (multi-provider) ```tsx // src/lib/auth.ts import NextAuth from "next-auth"; import GitHub from "next-auth/providers/github"; import Google from "next-auth/providers/google"; import { PrismaAdapter } from "@auth/prisma-adapter"; import { db } from "@/lib/db"; export const { handlers, auth, signIn, signOut } = NextAuth({ adapter: PrismaAdapter(db), providers: [ GitHub({ clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET!, }), Google({ clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }), ], callbacks: { session({ session, user }) { session.user.id = user.id; return session; }, }, }); ``` ### Route handler ```tsx // src/app/api/auth/[...nextauth]/route.ts import { handlers } from "@/lib/auth"; export const { GET, POST } = handlers; ``` ### Middleware protection ```tsx // src/middleware.ts import { auth } from "@/lib/auth"; export default auth((req) => { if (!req.auth && req.nextUrl.pathname !== "/login") { return Response.redirect(new URL("/login", req.url)); } }); export const config = { matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico).*)"], }; ``` ### Session in Server Component ```tsx import { auth } from "@/lib/auth"; export default async function Page() { const session = await auth(); if (!session?.user) redirect("/login"); return