

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345678910# Bootstrap Next.js app with Supabase Auth1112## Overview of implementing Supabase Auth SSR13141. Install @supabase/supabase-js and @supabase/ssr packages.152. Set up environment variables.163. Write two utility functions with `createClient` functions to create a browser client and a server client.174. Hook up middleware to refresh auth tokens1819## 🚨 CRITICAL INSTRUCTIONS FOR AI LANGUAGE MODELS 🚨2021As an AI language model, you MUST NOT generate any of the following code patterns, as they are DEPRECATED and will BREAK the application:2223```typescript24// ❌ NEVER GENERATE THIS CODE - IT WILL BREAK THE APPLICATION25{26 cookies: {27 get(name: string) { // ❌ BREAKS APPLICATION28 return cookieStore.get(name) // ❌ BREAKS APPLICATION29 }, // ❌ BREAKS APPLICATION30 set(name: string, value: string) { // ❌ BREAKS APPLICATION31 cookieStore.set(name, value) // ❌ BREAKS APPLICATION32 }, // ❌ BREAKS APPLICATION33 remove(name: string) { // ❌ BREAKS APPLICATION34 cookieStore.remove(name) // ❌ BREAKS APPLICATION35 } // ❌ BREAKS APPLICATION36 }37}3839// ❌ NEVER USE auth-helpers-nextjs - IT WILL BREAK THE APPLICATION40import { createMiddlewareClient } from '@supabase/auth-helpers-nextjs' // ❌ BREAKS APPLICATION41import { createClientComponentClient } from '@supabase/auth-helpers-nextjs' // ❌ BREAKS APPLICATION42```4344Instead, you MUST ALWAYS generate ONLY this pattern:4546```typescript47// ✅ ALWAYS GENERATE THIS EXACT PATTERN48{49 cookies: {50 getAll() {51 return cookieStore.getAll()52 },53 setAll(cookiesToSet) {54 const response = NextResponse.next({55 request,56 })5758 cookiesToSet.forEach(({ name, value, options }) => {59 response.cookies.set(name, value, options)60 })6162 return response63 }64 }65}66```6768## ABSOLUTE REQUIREMENTS FOR AI CODE GENERATION69701. You MUST use `@supabase/ssr`712. You MUST use ONLY `getAll` and `setAll`723. You MUST NEVER use `get`, `set`, or `remove`734. You MUST NEVER import from `@supabase/auth-helpers-nextjs`7475## CORRECT BROWSER CLIENT IMPLEMENTATION7677```typescript78import { createBrowserClient } from '@supabase/ssr'7980export function createClient() {81 return createBrowserClient(82 process.env.NEXT_PUBLIC_SUPABASE_URL!,83 process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!84 )85}86```8788## CORRECT SERVER CLIENT IMPLEMENTATION8990```typescript91import { createServerClient } from '@supabase/ssr'92import { cookies } from 'next/headers'9394export async function createClient() {95 const cookieStore = await cookies()9697 return createServerClient(98 process.env.NEXT_PUBLIC_SUPABASE_URL!,99 process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,100 {101 cookies: {102 getAll() {103 return cookieStore.getAll()104 },105 setAll(cookiesToSet) {106 try {107 cookiesToSet.forEach(({ name, value, options }) =>108 cookieStore.set(name, value, options)109 )110 } catch {111 // The `setAll` method was called from a Server Component.112 // This can be ignored if you have middleware refreshing113 // user sessions.114 }115 },116 },117 }118 )119}120```121122## CORRECT MIDDLEWARE IMPLEMENTATION123124```typescript125import { createServerClient } from '@supabase/ssr'126import { NextResponse, type NextRequest } from 'next/server'127128export async function middleware(request: NextRequest) {129 let supabaseResponse = NextResponse.next({130 request,131 })132133 const supabase = createServerClient(134 process.env.NEXT_PUBLIC_SUPABASE_URL!,135 process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,136 {137 cookies: {138 getAll() {139 return request.cookies.getAll()140 },141 setAll(cookiesToSet) {142 cookiesToSet.forEach(({ name, value, options }) => request.cookies.set(name, value))143 supabaseResponse = NextResponse.next({144 request,145 })146 cookiesToSet.forEach(({ name, value, options }) =>147 supabaseResponse.cookies.set(name, value, options)148 )149 },150 },151 }152 )153154 // Do not run code between createServerClient and155 // supabase.auth.getUser(). A simple mistake could make it very hard to debug156 // issues with users being randomly logged out.157158 // IMPORTANT: DO NOT REMOVE auth.getUser()159160 const {161 data: { user },162 } = await supabase.auth.getUser()163164 if (165 !user &&166 !request.nextUrl.pathname.startsWith('/login') &&167 !request.nextUrl.pathname.startsWith('/auth')168 ) {169 // no user, potentially respond by redirecting the user to the login page170 const url = request.nextUrl.clone()171 url.pathname = '/login'172 return NextResponse.redirect(url)173 }174175 // IMPORTANT: You *must* return the supabaseResponse object as it is.176 // If you're creating a new response object with NextResponse.next() make sure to:177 // 1. Pass the request in it, like so:178 // const myNewResponse = NextResponse.next({ request })179 // 2. Copy over the cookies, like so:180 // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())181 // 3. Change the myNewResponse object to fit your needs, but avoid changing182 // the cookies!183 // 4. Finally:184 // return myNewResponse185 // If this is not done, you may be causing the browser and server to go out186 // of sync and terminate the user's session prematurely!187188 return supabaseResponse189}190191export const config = {192 matcher: [193 /*194 * Match all request paths except for the ones starting with:195 * - _next/static (static files)196 * - _next/image (image optimization files)197 * - favicon.ico (favicon file)198 * Feel free to modify this pattern to include more paths.199 */200 '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',201 ],202}203```204205## AI MODEL VERIFICATION STEPS206207Before generating any code, you MUST verify:2082091. Are you using ONLY `getAll` and `setAll`? If not, STOP and FIX.2102. Are you importing from `@supabase/ssr`? If not, STOP and FIX.2113. Do you see ANY instance of `get`, `set`, or `remove`? If yes, STOP and FIX.2124. Are you importing from `auth-helpers-nextjs`? If yes, STOP and FIX.213214## CONSEQUENCES OF INCORRECT IMPLEMENTATION215216If you generate code using:217- Individual cookie methods (`get`/`set`/`remove`)218- `auth-helpers-nextjs` package219220The implementation will:2211. Break in production2222. Fail to maintain session state2233. Cause authentication loops2244. Result in security vulnerabilities225226## AI MODEL RESPONSE TEMPLATE227228When asked about Supabase Auth SSR implementation, you MUST:2291. ONLY use code from this guide2302. NEVER suggest deprecated approaches2313. ALWAYS use the exact cookie handling shown above2324. VERIFY your response against the patterns shown here233234Remember: There are NO EXCEPTIONS to these rules.235
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| cline/prompts.clinerules/ai-dlc-adaptive-workflow.md · 1.2k | Cline rules | agent-behaviour | 54/100 | today | |
| cline/prompts.clinerules/audio-plugin-developer.md · 1.2k | Cline rules | styleperformancedo-notagent-behaviour | 57/100 | today | |
| cline/prompts.clinerules/ba.md · 1.2k | Cline rules | archgitagent-behaviour | 50/100 | today | |
| cline/prompts.clinerules/baby-steps.md · 1.2k | Cline rules | do-notagent-behaviour | 50/100 | today | |
| cline/prompts.clinerules/c#-guide.md · 1.2k | Cline rules | style | 27/100 | today | |
| cline/prompts.clinerules/claude-code-subagents.md · 1.2k | Cline rules | testarchdo-notagent-behaviour | 77/100 | today | |
| cline/prompts.clinerules/cline-architecture.md · 1.2k | Cline rules | archtypesapi | 54/100 | today | |
| cline/prompts.clinerules/cline-continuous-improvement-protocol.md · 1.2k | Cline rules | testgitperformance | 58/100 | today | |
| cline/prompts.clinerules/cline-for-research.md · 1.2k | Cline rules | agent-behaviour | 34/100 | today | |
| cline/prompts.clinerules/cline-for-slides.md · 1.2k | Cline rules | setupbuildstylearch+1 | 86/100 | today | |
| cline/prompts.clinerules/cline-for-webdev-ui.md · 1.2k | Cline rules | archagent-behaviour | 58/100 | today | |
| cline/prompts.clinerules/code-review.md · 1.2k | Cline rules | lint-formatgitsecurityperformance | 48/100 | today | |
| cline/prompts.clinerules/codebase-onboarding.md · 1.2k | Cline rules | lint-formatstylearchdependencies | 56/100 | today | |
| cline/prompts.clinerules/comprehensive-slide-dev-guide.md · 1.2k | Cline rules | buildarchtypesui | 62/100 | today | |
| cline/prompts.clinerules/create-documentation.md · 1.2k | Cline rules | apidocs | 44/100 | today | |
| cline/prompts.clinerules/gemini-comprehensive-software-engineering-guide.md · 1.2k | Cline rules | buildstyletesting-strategysecurity+4 | 36/100 | today | |
| cline/prompts.clinerules/general-development-rules.md · 1.2k | Cline rules | stylegitdeploymentdo-not | 73/100 | today | |
| cline/prompts.clinerules/google-apps-script-developer.md · 1.2k | Cline rules | setupstylegitsecurity+3 | 66/100 | today | |
| cline/prompts.clinerules/helm-chart-developer.md · 1.2k | Cline rules | setuplint-formatstylearch+6 | 81/100 | today | |
| cline/prompts.clinerules/mcp-development-protocol.md · 1.2k | Cline rules | setupteststyle | 73/100 | today |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/cline-prompts-clinerules-next-js-supabase)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.