Fix Supabase: Invalid Refresh Token Already Used
Trace which client retains an old Supabase token, preserve refreshed response cookies, and let the affected browser sign in again without a global logout.
Explore our curated collection of articles, insights, and stories about Supabase.
Trace which client retains an old Supabase token, preserve refreshed response cookies, and let the affected browser sign in again without a global logout.
A Stack Overflow question with 14 votes and no accepted answer, and the GitHub issue the same reporter filed a month later with minification turned off. Together they show exactly which import fails, and that this bug was never really fixed — only avoided.
Why Firebase Google sign-in rejects redirect and hangs on popup once a web app is saved to an iPhone Home Screen, straight from the engineer who answered the issue.
A pre-launch checklist for Supabase magic link and email-OTP sign-in: the mailer cap, the redirect allow list, the PKCE email template, and the link-scanner problem that burns single-use tokens.
Reproduced on firebase 8.10.1, 9.23.0 and 13.0.0: which declaration file rejects the options object, what disableWarnings really silences in each version, and the two fixes that compile.
Three different errors hide behind one symptom, and only one of them is about the emulator. Two were reproduced with linkWithRedirect against the emulator, the API key one with the emulator disconnected.
Your login button can come back to life a fraction of a second after the user closes the Google popup, without patching the SDK or breaking slow sign-ins.
The rejection happens one function call earlier than most people expect, before any server, project or emulator is ever reached.
The embed is not broken — PostgREST just cannot guess which of two many-to-many paths you meant, and it tells you both candidates in the error body.
Trace the two Enterprise script loaders, confirm which Firebase release contains the repair, and distinguish a stale SDK from a genuine key configuration problem.
Keep the Next.js app on Vercel and make the Google sign-in screen name your own domain instead of the project-id.firebaseapp.com subdomain.
Why passing firebaseConfig to getFirestore() breaks inside the Firebase SDK, reproduced on firebase 9.0.0 and 13.0.0, with the corrected Next.js module and the wrapper that only hid the bug.
The emulator call from the Stack Overflow question, reproduced with the Node SDK against a real Firestore emulator: what the SDK builds from the host string, which other causes give the same error, and which do not.
Read the two version requirements behind this Firebase install failure, reproduce the prerelease mismatch, and select a stable dependency tree.
Why rapid listener churn can push a Firestore bookkeeping counter below zero, which part of this is actually fixed, and the one mitigation reporters say works when upgrading does not.
A static Next.js export deploys cleanly to Firebase Hosting, yet every page but the homepage 404s. Reproduced locally, with the config that actually fixes it.
Why Next.js reloads turn a harmless emulator warning into a hard FirebaseError, what changed in the modular SDK, and a setup that survives every reload.
firebase deploy says this "should have caused an error earlier". With a single hosting object and a dead login it did, and the CLI threw it away. Both causes, reproduced on firebase-tools 15.32.1, and how to tell them apart.
The build server runs npm ci with a stricter config than your laptop. Here is why that produces dozens of "Missing" lines on a lockfile that installs fine locally, reproduced end to end.
The error reads like a typo in a URL, but almost every case is a build-time environment variable that never made it into the bundle.
Magic links and password-reset emails that always land on the production Site URL instead of the redirectTo you passed. The allow-list mechanism behind it, and the wildcard pattern for local dev and preview branches.
Supabase's auth warning means two GoTrueClient instances are racing over the same localStorage session key. The singleton pattern that fixes it, and the case where a second auth provider is the real cause.
Solve the Prisma 'prepared statement s0 already exists' error caused by Supabase pooling. Add directUrl, enable pgbouncer mode, and verify your connection.
Prisma errors out with missing DATABASE_URL when the .env file isn't loaded. Trigger prisma generate and get your GraphQL query running again.
The warning fires on every image, upload and WebSocket that touches <ref>.supabase.co in Firefox. It is Cloudflare's bot-management cookie being scoped to a Public Suffix List domain, so every browser drops it. Here is the verified cause, the cases where the noise hides a real 403 or auth bug, and how to tell them apart in two minutes.
A Supabase Edge Function that returns BOOT_ERROR or "failed to bootstrap runtime" is failing before your code even runs. Here is how to isolate which of the four common causes is yours.
Supabase Auth integrates identity with Supabase APIs and RLS. Better Auth keeps auth in your application; database policies remain possible when you deliberately propagate a verified identity under a restricted role.
`AuthSessionMissingError: Auth session missing!` is not a bug report — it is Supabase telling you, accurately, that the client you called had no session to work with. The hard part is that the same message covers a signed-out user, a server client that never received your cookies, a middleware that forgot to forward them, and a session the Auth server has already ended. Each has a different fix.
Your app loads, the session arrives, and then every Supabase call after it hangs forever. No error, no rejected promise, no network request — the query simply never returns and the loading spinner stays up until someone reloads the page. If you fetch a profile inside your `onAuthStateChange` callback, this is a documented deadlock in supabase-js, and the fix is one line.
A view over `auth.users`, a policy that joins it, or a client query against it all fail the same way: `ERROR: 42501: permission denied for schema auth`. It is not a missing GRANT you forgot — Supabase keeps the `auth` schema out of reach of the API roles deliberately, and granting your way in is the one fix you should not apply. The supported route is a security definer function.
Every RLS leak I have seen shipped the same way: the policy was tested in a context that does not enforce it. The Supabase SQL editor runs as a privileged role, the service key carries `BYPASSRLS`, and the table owner is exempt from its own policies unless you say otherwise. Three green checks, zero enforcement. This is the procedure that actually tests a policy — plus the two Postgres flags that decide whether your test means anything.
The Firestore error "PERMISSION_DENIED: Missing or insufficient permissions" never tells you which rule rejected you. Here is how to find out — and the seven causes that account for almost every occurrence.
Firebase ships two databases and the official comparison page is diplomatic about it. The numbers are not: query model, pricing units, connection limits and region availability all point the same way for a new build in 2026.
Signups fail with "Database error saving new user" the moment you add a trigger on auth.users. The trigger threw, the transaction rolled back, and auth.users never got the row. Here is the fix.
Supabase asks every new signup to confirm their email before they can sign in. In local dev that is noise. Here are three ways to skip it, and the one production rule you must not break.
After Supabase OAuth sign-in, access_token and refresh_token hash fragments linger in the browser URL. Here is why the implicit flow leaks them and how PKCE (or a one-line hash cleanup) strips them.
The Supabase auth-js "using getSession() is insecure" warning floods your server logs on every request. Here is why getUser() fixes it and where getSession() is still safe to call.
Check which APIs a public Firebase key can call, protect data with rules, and initialise App Check before turning on enforcement.
Your auth looks correct but users can bypass it. The bug: getSession() in server code reads from local storage without revalidating the token against the Auth server.
The redirect silently lands on your production domain instead of the preview URL, with no error from Supabase. Here is the exact Supabase dashboard config and the Vercel env var pattern.
A Supabase Realtime subscription can say SUBSCRIBED and still receive nothing. This fix walks through RLS, filter syntax, stale React subscriptions, paused projects, and broadcast versus postgres_changes confusion.
This is not another feature table that ends with 'it depends.' Clerk wins for polished B2B auth and org-heavy products; Supabase Auth wins when database-native simplicity, price, and RLS integration matter more.
RLS failures are rarely random. This checklist walks through the same order I use in production: confirm RLS is enabled, prove the role and JWT claims, then isolate USING, WITH CHECK, and service-role bypass mistakes.
If you are fetching whole result sets just to count them, you are paying for bandwidth and latency you do not need. Supabase already returns counts in query metadata.
This Storage error almost never means Supabase is broken. It usually means your upload path, your RLS policy, or your use of `upsert` does not match how Storage actually authorizes writes.
Supabase does support joins, but not with the SQL string most people expect. The API uses embedded relations, and a few small syntax rules change the result shape completely.
The Supabase service_role key bypasses every RLS policy in your database. That is exactly what you want for admin jobs, migrations, and cron tasks — and exactly what an attacker wants if it ever leaks to the client bundle. Here is how to set up the admin client in Next.js, where it is safe to use, and the three mistakes that put a root credential in your JS bundle.
Learn a practical pattern for inserting into multiple tables with one Supabase API call by using a server‑side function and a transaction.
Learn the exact steps to grant the right permissions in Supabase and stop the 'permission denied for schema public' error from breaking your app.
Supabase Auth returns precise error codes — `invalid_credentials`, `weak_password`, `same_password`, `email_not_confirmed` — but most apps collapse them all into "Something went wrong." Here's the full TypeScript enum, a typed handler, and the UX pattern that doubles signup completion.
If your Supabase query returns `infinite recursion detected in policy for relation "X"`, your RLS policy is querying the same table it protects. Here's exactly why it loops, and three production-grade fixes that don't leak data.
A grounded comparison of the four major Next.js auth options — including the middleware vulnerability that changed everything, real MAU pricing math, and which architecture actually scales.
Eleven recurring traps that surface once Supabase Auth is wired into a production Next.js app — drawn from public Supabase docs, the SSR guide, and the postmortems the community has published.
A from-scratch, production-ready chat app built with Next.js 15 App Router and Supabase Realtime. Schema, non-recursive RLS, presence, typing indicators, infinite scrollback, and the production gotchas.
A from-scratch, docs-grounded guide to wiring Google OAuth into a Next.js 15 App Router app with Supabase. Every redirect URL, every scope, every silent failure — fixed.
Every Supabase auth edge case in one guide: session refresh in middleware, cookie handling across server and client, redirect URLs that actually work, MFA flows, token rotation, and the silent failures nobody warns you about.
Slow Supabase queries kill your app feel and inflate your bill. Here are the six causes I keep seeing in production apps, and the exact SQL and code fixes for each one.
Build a complete full-stack application with Next.js and Supabase from scratch. Authentication, database, CRUD operations, and deployment — all in 20 minutes.
Supabase vs Firebase — which backend should you pick in 2026? We compare pricing, performance, developer experience, and scalability with real benchmarks and code examples.
Complete guide to file uploads, image optimization, CDN integration, and media management with Supabase Storage and Next.js. Learn signed URLs, progressive uploads, and production-ready patterns.
Master advanced authentication patterns including OAuth, magic links, passwordless auth, custom JWT, multi-tenant authentication, and enterprise SSO integration with Next.js and Supabase.
After shipping multiple production apps with Next.js and Supabase, here are the decisions that cost the most time to undo — and what I'd do instead from day one.
Next.js serverless functions have a 10-second execution limit. Learn how to handle long-running tasks, background jobs, and async processing using Supabase Edge Functions, database queues, and pg_cron without external job queue services.
Understand exactly how Supabase session management works in Next.js App Router — cookies, middleware, Server Components, and Client Components — and why getting it wrong causes silent auth failures.
Go beyond simple auth.uid() checks. Learn advanced Row Level Security policy patterns for multi-role systems, team-based access, hierarchical permissions, and performance-safe RLS in production Supabase apps.
Build scalable multi-tenant SaaS applications with Next.js and Supabase. Complete guide to tenant isolation, RLS policies, subdomain routing, and billing integration for production apps.
Avoid these critical mistakes when building with Next.js and Supabase. Learn from real-world errors that cost developers hours of debugging and discover proven solutions.
Complete guide to building and deploying Supabase Edge Functions with Next.js. Learn serverless functions, Deno runtime, database triggers, webhooks, scheduled jobs, and real-world use cases.
Supabase auth sessions mysteriously disappearing after page refresh? Learn the exact cause and fix it in 5 minutes with this tested solution.
Auth errors crashing your Next.js middleware? Learn how to handle Supabase auth errors gracefully with proper error handling patterns.
Auth redirect not working after Supabase sign-in? Here are the three root causes and the exact fixes — callback route, redirect URL allowlist, and router.refresh().
Master full-stack SaaS development with Next.js 15 and Supabase. From database design to deployment, learn everything you need to build production-ready applications.
Email confirmations not sending from Supabase? Learn the exact causes and fixes for SMTP, template, and configuration issues in 10 minutes.