sitharaj88/claude-skills/auth-setup

Claude Code and agent skill by sitharaj88/claude-skills

Trust tier 3
  • community
Source check pending

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-setup

SKILL.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: next in package.json + app/ directory — auth belongs in middleware.ts, Route Handlers (app/api/*/route.ts), and Server Components
  • Next.js Pages Router: pages/ directory — getServerSideProps checks + 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-auth in 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, or custom
  • $1 = Primary flow: oauth, credentials, magic-link, or passkeys

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:

AUTH_SECRET=<generate with: npx auth secret or openssl rand -base64 32>
AUTH_GOOGLE_ID=<your-google-oauth-client-id>
AUTH_GOOGLE_SECRET=<your-google-oauth-client-secret>
DATABASE_URL=<your-database-url>

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 state parameter (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:

  1. Middleware (middleware.ts) as the coarse filter: redirect unauthenticated users from a matcher-scoped set of paths to /login?callbackUrl=...
  2. Server-side re-check in every protected handler: const session = await auth() (Auth.js), await auth() from Clerk, supabase.auth.getUser() (never trust getSession() alone server-side), or auth.api.getSession({ headers }) (Better-Auth) — return 401/redirect if absent
  3. Roles/permissions checked server-side: a role column or Clerk sessionClaims/organization roles; generate a requireRole("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 Passkey provider (@simplewebauthn/server + WebAuthn adapter tables), Better-Auth passkey() plugin, or Clerk's built-in passkeys. Register as residentKey: "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 React cache() in Next.js), plus the client hook (useSession from next-auth/react, Clerk's useUser, or Better-Auth's authClient.useSession)
  • Minimal login/logout UI wired to the provider's sign-in/sign-out actions
Step 9: Verify
  • Run the typecheck/build (npx tsc --noEmit or the project's build script)
  • Confirm middleware matcher excludes 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.example only
  • Rate-limit login, signup, and password-reset endpoints (e.g. @upstash/ratelimit or 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=Lax minimum; __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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/sitharaj88/claude-skills/auth-setup/badge)](https://verified-skill.com/skills/sitharaj88/claude-skills/auth-setup)

Something wrong with this skill or its page? Tell us.