supabase-auth
Skill141 starsChanged 34 days agoUnlicenseView on GitHub
Wire Supabase Auth into this Next.js 16 app with @supabase/ssr — browser/server clients, the proxy.ts session refresh (Next 16 renamed middleware), getClaims vs getSession, protected routes and sign-in flows. Use when the user asks for login, accounts, a client portal, gated content, or "add auth". Not needed for a plain marketing site.
- Reads credentials
- Installs packages
2 other projects use a version of this.
Adopted by
Most recently taken up by
- koach08/claude-code-skillstheir own version, first seen Sep 12, 2026
- Nice-Wolf-Studio/claude-code-supabase-skillstheir own version, first seen Oct 20, 2025
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Nice-Wolf-Studio/claude-code-supabase-skills★ 19same name
- koach08/claude-code-skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- aeo-visibilitySkill
- figma-to-sectionSkill
- i18n-seoSkill
- local-seoSkill
- mobile-device-qaSkill
- optimize-3d-sceneSkill
- optimize-loadSkill
- optimize-performanceSkill
- payload-adminSkill
- payload-analyticsSkill
- payload-cmsSkill
- qa-verifySkill
- schema-markupSkill
- seo-auditSkill
- seo-growSkill
- ship-checkSkill
- site-migrationSkill
- supabase-dbSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Only reach for this if the project genuinely needs user accounts.
- Very specific: line 144
Return
supabaseResponseunmodified: If you must build a new response, pass { request } and copy every cookie across, or the refreshed …
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Supabase Auth in Next.js 16
Only reach for this if the project genuinely needs user accounts. A marketing site backed by Payload does not — Payload has its own admin auth, and adding Supabase Auth on top is pure complexity.
Verified 2026-08 against @supabase/ssr 0.12.4.
The Next.js 16 wrinkle
middleware.ts no longer exists — it is proxy.ts, exporting a function
named proxy, running on Node (the Edge runtime is gone and cannot be
configured). Next's guidance is the "thin proxy" pattern: cheap cookie checks and
redirects only. Session refresh is fine there; heavy authorisation is not.
yarn add @supabase/supabase-js @supabase/ssrEnv: NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
(both zod-validated in src/env.ts).
Three clients, three files
src/lib/supabase/client.ts — browser:
import { createBrowserClient } from '@supabase/ssr'
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!
)
}src/lib/supabase/server.ts — Server Components, Route Handlers, Actions:
import { createServerClient } from '@supabase/ssr'
import { cookies } from 'next/headers'
export async function createClient() {
const cookieStore = await cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet, _headers) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
)
} catch {
// Called from a Server Component — safe to ignore when the proxy
// is refreshing sessions.
}
},
},
}
)
}src/lib/supabase/proxy.ts — the session refresher:
import { createServerClient } from '@supabase/ssr'
import { NextResponse, type NextRequest } from 'next/server'
export async function updateSession(request: NextRequest) {
let supabaseResponse = NextResponse.next({ request })
// With Fluid compute, never hoist this client into a module-level variable.
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
{
cookies: {
getAll() {
return request.cookies.getAll()
},
setAll(cookiesToSet, headers) {
cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))
supabaseResponse = NextResponse.next({ request })
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options)
)
Object.entries(headers).forEach(([key, value]) =>
supabaseResponse.headers.set(key, value)
)
},
},
}
)
// Do not run code between createServerClient and getClaims().
const { data } = await supabase.auth.getClaims()
const user = data?.claims
if (!user && !request.nextUrl.pathname.startsWith('/login')) {
const url = request.nextUrl.clone()
url.pathname = '/login'
return NextResponse.redirect(url)
}
return supabaseResponse
}src/proxy.ts — the entry point:
import { type NextRequest } from 'next/server'
import { updateSession } from '@/lib/supabase/proxy'
export async function proxy(request: NextRequest) {
return await updateSession(request)
}
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
}The three rules that cause every mystery bug
- Never trust
getSession()in server code. It reads the cookie without revalidating. UsegetClaims()(verifies the JWT signature against the project's published keys) orgetUser()(round-trips to Supabase). - Never put code between
createServerClientandgetClaims()in the proxy. It desynchronises cookie refresh and logs users out at random. - Return
supabaseResponseunmodified. If you must build a new response, pass{ request }and copy every cookie across, or the refreshed session is dropped.
Authorisation still lives in the database
The proxy redirect is UX, not security — it only checks a cookie. Real access
control is RLS (see the supabase-db skill). Assume every client-side query
is attacker-controlled and let Postgres decide.
Fits with this starter
- The auth form is a client leaf; the page and view stay Server Components.
- Motion on the form obeys hard rule #1 — springs, not CSS keyframes.
- Sign-in/out actions live in Route Handlers or Server Actions, never as direct
third-party calls from the browser (
obsidian/backend/api-architecture.md). - Adding
proxy.tsmeans every matched route runs Node before serving — keep the matcher tight so static marketing pages are not dragged through it.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

