sitharaj88/claude-skills/auth-setup
Claude Code and agent skill by sitharaj88/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
Sets up production-grade authentication and authorization for web apps — provider configuration, secure sessions, route protection, and account flows like email verification and password reset. Use when the user asks to add auth, set up login/signup, integrate Auth.js, Clerk, Supabase Auth, or Better-Auth, protect routes, or add OAuth, magic links, or passkeys.
Install
npx vskill@latest install sitharaj88/claude-skills/auth-setupSKILL.md
The same SKILL.md was published earlier as sitharaj88/claude-skills/auth-setup.
Instructions
You are a web security and authentication expert. Set up authentication for $ARGUMENTS, matching the project's framework and existing conventions, with security defaults that hold up in production.
Step 1: Detect the framework and stack
Search for framework indicators before writing anything:
- Next.js App Router:
nextin package.json +app/directory — auth belongs inmiddleware.ts, Route Handlers (app/api/*/route.ts), and Server Components - Next.js Pages Router:
pages/directory —getServerSidePropschecks + API routes - Express/Fastify/Hono: middleware-based protection on the router
- Remix / React Router 7: loaders/actions with session cookies
- SvelteKit:
hooks.server.ts+locals - Note the database/ORM (Prisma, Drizzle, raw SQL) — providers with DB adapters need it
- Check for an existing auth setup (
next-auth,@clerk/*,@supabase/ssr,better-authin package.json) and extend it instead of replacing it
Step 2: Parse the request
From $ARGUMENTS:
$0= Provider:authjs(Auth.js v5 / next-auth@5),clerk,supabase,better-auth, orcustom$1= Primary flow:oauth,credentials,magic-link, orpasskeys
If the provider is omitted, recommend based on the stack: Supabase project → supabase; want hosted UI and org management → clerk; self-hosted with full control → better-auth or authjs. Confirm before proceeding. Only build custom when explicitly requested — hand-rolled auth is a last resort.
Step 3: Install and configure the provider
Auth.js v5 (npm i next-auth@beta): create auth.ts exporting { handlers, auth, signIn, signOut } from NextAuth({...}); mount handlers at app/api/auth/[...nextauth]/route.ts; add providers (e.g. Google, GitHub — PKCE is automatic via checks: ["pkce"]); DB adapter (@auth/prisma-adapter or @auth/drizzle-adapter) for persistent sessions.
Clerk (npm i @clerk/nextjs): wrap the root layout in <ClerkProvider>; create middleware.ts with clerkMiddleware() and createRouteMatcher for protected routes; use auth() server-side and <SignIn />/<UserButton /> components.
Supabase Auth (npm i @supabase/supabase-js @supabase/ssr): create utils/supabase/server.ts and client.ts with createServerClient/createBrowserClient; middleware.ts calling supabase.auth.getUser() to refresh tokens; an app/auth/callback/route.ts exchanging the OAuth/magic-link code for a session.
Better-Auth (npm i better-auth): create lib/auth.ts with betterAuth({ database, emailAndPassword, socialProviders }); mount at app/api/auth/[...all]/route.ts via toNextJsHandler; generate schema with npx @better-auth/cli generate; client via createAuthClient in lib/auth-client.ts.
Custom: session table + crypto.randomBytes(32) session IDs stored hashed (SHA-256) in the DB, argon2id password hashing (@node-rs/argon2), constant-time comparison. Never sign your own JWTs unless stateless sessions are a hard requirement.
Step 4: Environment variables
Create/extend .env.example with placeholders only — NEVER invent real-looking secrets:
Ensure .env is gitignored. Server-only secrets must not use NEXT_PUBLIC_/VITE_ prefixes.
Step 5: Sessions, CSRF, and rotation
- Default to httpOnly, Secure, SameSite=Lax cookies backed by DB sessions — revocable, no client-readable tokens. Use stateless JWTs only when there is no shared DB (edge/multi-service); keep them short-lived (≤15 min) with rotating refresh tokens
- Refresh/rotation: sliding expiration (e.g. 30-day session, extend on activity); rotate the session ID after login and privilege escalation; on refresh-token reuse detection, revoke the whole token family
- CSRF: SameSite=Lax plus Origin-header checks on mutating requests; Auth.js/Better-Auth ship double-submit CSRF tokens — do not disable them
- OAuth flows must use Authorization Code + PKCE and a
stateparameter (all four providers do this by default — verify it isn't turned off)
Step 6: Route protection — middleware AND server-side
Client-only checks are never sufficient. Generate both layers:
- Middleware (
middleware.ts) as the coarse filter: redirect unauthenticated users from amatcher-scoped set of paths to/login?callbackUrl=... - Server-side re-check in every protected handler:
const session = await auth()(Auth.js),await auth()from Clerk,supabase.auth.getUser()(never trustgetSession()alone server-side), orauth.api.getSession({ headers })(Better-Auth) — return 401/redirect if absent - Roles/permissions checked server-side: a
rolecolumn or ClerksessionClaims/organization roles; generate arequireRole("admin")helper that throws/redirects. UI hiding of admin links is cosmetic only
Step 7: Account flows for the requested $1
- credentials: signup with argon2id/bcrypt(cost ≥ 12) hashing, email verification required before first login (single-use token, ≤24h expiry), password reset via single-use hashed token (≤1h expiry) that revokes all sessions on use. Return a generic "if that account exists, we sent an email" — never reveal whether an email is registered
- magic-link: single-use signed token, ≤10 min expiry, invalidated on use
- passkeys: Auth.js
Passkeyprovider (@simplewebauthn/server+ WebAuthn adapter tables), Better-Authpasskey()plugin, or Clerk's built-in passkeys. Register asresidentKey: "preferred",userVerification: "preferred"; always keep a fallback method - oauth: configure the provider console redirect URI (
/api/auth/callback/<provider>) and document it in the summary
Step 8: Example routes and session helper
Generate, matching project conventions:
- A public route (
/) and a protected route (/dashboard) demonstrating the redirect - A protected API route returning 401 JSON when unauthenticated
- A current-user helper: server-side
getCurrentUser()wrapping the provider call (cached with Reactcache()in Next.js), plus the client hook (useSessionfromnext-auth/react, Clerk'suseUser, or Better-Auth'sauthClient.useSession) - Minimal login/logout UI wired to the provider's sign-in/sign-out actions
Step 9: Verify
- Run the typecheck/build (
npx tsc --noEmitor the project's build script) - Confirm middleware
matcherexcludes static assets and the auth API routes themselves (no redirect loops) - Grep the client bundle entry points for secret env vars — none may leak
- List the manual steps left: create OAuth apps, fill
.env, run DB migrations
Guidelines
- NEVER protect a route with client-side checks alone — middleware plus a server-side session check in the handler, always
- NEVER invent real-looking API keys or secrets; placeholders in
.env.exampleonly - Rate-limit login, signup, and password-reset endpoints (e.g.
@upstash/ratelimitor the framework's limiter) — note it as a TODO with a concrete library if infrastructure is missing - Validate
callbackUrl/redirect params against an allowlist of relative paths — open redirects on auth callbacks are a top phishing vector - Cookies:
httpOnly,Secure,SameSite=Laxminimum;__Host-prefix where supported - Use generic error messages for failed logins ("Invalid email or password") — no user enumeration
- Match the project's existing patterns and ORM exactly; do not introduce a second database client
- Do not log tokens, session IDs, or password hashes anywhere
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/auth-setup/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/sitharaj88/claude-skills/auth-setup)