dinaf2026-web/awesome-web-skills/web-auth

Claude Code and agent skill by dinaf2026-web/awesome-web-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Next.js 14 App Router authentication patterns. Covers NextAuth v5, Clerk, and Supabase Auth end-to-end: setup, protected routes, RBAC, OAuth, session handling in Server and Client Components, UI state, and security rules.

Install

npx vskill@latest install dinaf2026-web/awesome-web-skills/web-auth

SKILL.md

The same SKILL.md was published earlier as dinaf2026-web/awesome-web-skills/web-auth.

web-auth — Next.js 14 App Router Authentication

1. Decision Table — NextAuth vs Clerk vs Supabase Auth

CriterionNextAuth v5ClerkSupabase Auth
CostFree (OSS)Free tier; paid for orgs/MFAFree tier; usage-based
Setup timeMedium (~1 hr)Fast (~20 min)Medium (~45 min)
UI componentsNone (bring your own)Pre-built, customizableNone (bring your own)
DatabaseAny via adapterClerk-managedSupabase Postgres
Row-Level SecurityManualNoNative (RLS)
Organizations / TeamsManualBuilt-inManual
SSR / RSC supportYes (v5)YesYes (SSR pkg)
MFA / PasskeysManualBuilt-inBuilt-in
Best forFull control, custom DBRapid dev, B2B SaaSApps already on Supabase

Pick NextAuth v5 when you own the database and need full control over the auth flow. Pick Clerk when you need org management, device sessions, or polished pre-built UI fast. Pick Supabase Auth when your data already lives in Supabase and you want RLS.


2. NextAuth v5 — Full Setup

Install
bash
npm install next-auth@beta
auth.ts — core config
typescript
// auth.ts (project root)
import NextAuth from 'next-auth'
import GitHub from 'next-auth/providers/github'
import Google from 'next-auth/providers/google'
import Credentials from 'next-auth/providers/credentials'
import { PrismaAdapter } from '@auth/prisma-adapter'
import { prisma } from '@/lib/prisma'
import bcrypt from 'bcryptjs'
import { z } from 'zod'
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
session: { strategy: 'jwt' },
pages: {
signIn: '/login',
error: '/login',
},
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!,
}),
Credentials({
credentials: {
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
const parsed = z.object({
email: z.string().email(),
password: z.string().min(8),
}).safeParse(credentials)
if (!parsed.success) return null
const user = await prisma.user.findUnique({
where: { email: parsed.data.email },
})
if (!user?.hashedPassword) return null
const valid = await bcrypt.compare(parsed.data.password, user.hashedPassword)
if (!valid) return null
return { id: user.id, email: user.email, name: user.name, role: user.role }
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token.id = user.id
token.role = (user as any).role ?? 'user'
}
return token
},
async session({ session, token }) {
if (token) {
session.user.id = token.id as string
session.user.role = token.role as string
}
return session
},
},
})
TypeScript augmentation — add role and id to session
typescript
// types/next-auth.d.ts
import NextAuth from 'next-auth'
declare module 'next-auth' {
interface User {
role?: string
}
interface Session {
user: {
id: string
role: string
email: string
name?: string | null
image?: string | null
}
}
}
declare module 'next-auth/jwt' {
interface JWT {
id: string
role: string
}
}
Route handler
typescript
// app/api/auth/[...nextauth]/route.ts
import { handlers } from '@/auth'
export const { GET, POST } = handlers
Middleware
typescript
// middleware.ts
import { auth } from '@/auth'
import { NextResponse } from 'next/server'
export default auth((req) => {
const { pathname } = req.nextUrl
const isLoggedIn = !!req.auth
const publicPaths = ['/login', '/register', '/api/auth']
const isPublic = publicPaths.some((p) => pathname.startsWith(p))
if (!isLoggedIn && !isPublic) {
return NextResponse.redirect(new URL('/login', req.url))
}
return NextResponse.next()
})
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}
Login page with Server Action
typescript
// app/login/page.tsx
'use client'
import { signIn } from 'next-auth/react'
import { useRouter } from 'next/navigation'
import { useState } from 'react'
export default function LoginPage() {
const router = useRouter()
const [error, setError] = useState<string | null>(null)
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault()
const fd = new FormData(e.currentTarget)
const result = await signIn('credentials', {
email: fd.get('email'),
password: fd.get('password'),
redirect: false,
})
if (result?.error) {
setError('Invalid credentials')
} else {
router.push('/dashboard')
}
}
return (
<form onSubmit={handleSubmit} className="space-y-4 max-w-sm mx-auto mt-16">
{error && <p className="text-red-500 text-sm">{error}</p>}
<input name="email" type="email" placeholder="Email" required className="w-full border px-3 py-2 rounded" />
<input name="password" type="password" placeholder="Password" required className="w-full border px-3 py-2 rounded" />
<button type="submit" className="w-full bg-blue-600 text-white py-2 rounded">Sign in</button>
<button type="button" onClick={() => signIn('google')} className="w-full border py-2 rounded">
Continue with Google
</button>
</form>
)
}
Session in Server Component
typescript
// app/dashboard/page.tsx
import { auth } from '@/auth'
import { redirect } from 'next/navigation'
export default async function DashboardPage() {
const session = await auth()
if (!session) redirect('/login')
return <h1>Welcome, {session.user.name}</h1>
}
Required env vars
bash
# .env.local
AUTH_SECRET=<openssl rand -base64 32>
AUTH_URL=http://localhost:3000
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
DATABASE_URL=postgresql://...

3. Clerk — Middleware, Provider, Components, Hooks

Install
bash
npm install @clerk/nextjs
Middleware
typescript
// middleware.ts
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'
const isPublicRoute = createRouteMatcher([
'/sign-in(.*)',
'/sign-up(.*)',
'/api/webhooks(.*)',
'/',
])
export default clerkMiddleware((auth, req) => {
if (!isPublicRoute(req)) {
auth().protect()
}
})
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}
Root layout — ClerkProvider
typescript
// app/layout.tsx
import { ClerkProvider } from '@clerk/nextjs'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<ClerkProvider>
<html lang="en">
<body>{children}</body>
</html>
</ClerkProvider>
)
}
Pre-built auth pages
typescript
// app/sign-in/[[...sign-in]]/page.tsx
import { SignIn } from '@clerk/nextjs'
export default function Page() {
return <SignIn />
}
// app/sign-up/[[...sign-up]]/page.tsx
import { SignUp } from '@clerk/nextjs'
export default function Page() {
return <SignUp />
}
UserButton and navigation
typescript
// components/nav.tsx
'use client'
import { UserButton, SignInButton, SignedIn, SignedOut } from '@clerk/nextjs'
export function Nav() {
return (
<nav className="flex items-center justify-between p-4">
<span className="font-bold">MyApp</span>
<div className="flex items-center gap-4">
<SignedOut>
<SignInButton mode="modal">
<button className="bg-blue-600 text-white px-4 py-2 rounded">Sign in</button>
</SignInButton>
</SignedOut>
<SignedIn>
<UserButton afterSignOutUrl="/" />
</SignedIn>
</div>
</nav>
)
}
Client hooks — useAuth / useUser
typescript
// components/profile-card.tsx
'use client'
import { useAuth, useUser } from '@clerk/nextjs'
export function ProfileCard() {
const { isLoaded, isSignedIn, userId } = useAuth()
const { user } = useUser()
if (!isLoaded) return <div className="animate-pulse h-10 bg-gray-200 rounded" />
if (!isSignedIn) return null
return (
<div className="flex items-center gap-3">
<img src={user?.imageUrl} alt="" className="w-8 h-8 rounded-full" />
<span>{user?.fullName}</span>
<span className="text-xs text-gray-500">{userId}</span>
</div>
)
}
currentUser() in Server Components
typescript
// app/dashboard/page.tsx
import { currentUser } from '@clerk/nextjs/server'
import { redirect } from 'next/navigation'
export default async function DashboardPage() {
const user = await currentUser()
if (!user) redirect('/sign-in')
const role = user.publicMetadata.role as string | undefined
return (
<div>
<h1>Hello {user.firstName}</h1>
{role === 'admin' && <AdminPanel />}
</div>
)
}
Required env vars
bash
# .env.local
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard

4. Supabase Auth — SSR-Safe Clients, Middleware, Email, OAuth

Install
bash
npm install @supabase/supabase-js @supabase/ssr
Server client — for Server Components and Route Handlers
typescript
// lib/supabase/server.ts
import { createServerClient } from '@supabase/ssr'
import { cookies } from 'next/headers'
import type { Database } from '@/types/supabase'
export function createClient() {
const cookieStore = cookies()
return createServerClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
)
} catch {
// Ignore: Server Component can't set cookies (middleware handles it)
}
},
},
}
)
}
Browser client — for Client Components
typescript
// lib/supabase/client.ts
import { createBrowserClient } from '@supabase/ssr'
import type { Database } from '@/types/supabase'
export function createClient() {
return createBrowserClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
}
Middleware — refresh session on every request
typescript
// middleware.ts
import { createServerClient } from '@supabase/ssr'
import { NextResponse, type NextRequest } from 'next/server'
export async function middleware(request: NextRequest) {
let supabaseResponse = NextResponse.next({ request })
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return request.cookies.getAll()
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))
supabaseResponse = NextResponse.next({ request })
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options)
)
},
},
}
)
// Refresh session — MUST do this before any auth checks
const { data: { user } } = await supabase.auth.getUser()

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

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/dinaf2026-web/awesome-web-skills/web-auth/badge)](https://verified-skill.com/skills/dinaf2026-web/awesome-web-skills/web-auth)

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