- Symptom
- new row violates row-level security policy from a client built with the service_role or sb_secret keyAdmin queries return [] in a Next.js server action using createServerClientService role client stops bypassing RLS after calling signUp or signInWithPassword on it
- Cause
- RLS is decided by the Authorization header, not the apikey header. SSR clients copy the user session from cookies into that header, and auth calls on a shared client replace it with the user's JWT.
- Fix
- Build a separate admin client with plain createClient, no cookies, and session persistence off. Create users with auth.admin.createUser rather than signUp on that client.
- Apply
import { createClient } from '@supabase/supabase-js'; export const admin = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SECRET_KEY, { auth: { persistSession: false, autoRefreshToken: false }, });- Affected
- supabase-js 2.x and @supabase/ssr; legacy service_role keys and new secret keys alike
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders