Fix guides · Lovable, Bolt, Cursor, Claude Code ·
Fix Supabase "Invalid Refresh Token: Not Found"
AuthApiError: Invalid Refresh Token: Refresh Token Not Found
This Supabase Auth error means your app tried to refresh a login session with a refresh token that Supabase no longer has. That happens when an old session is still saved in the browser after the user signed out, the project changed, or the token was already used by another tab or server request. Usually the fix is to sign the user out cleanly when this happens and, in Next.js, refresh sessions in middleware with @supabase/ssr instead of in several places at once.
Common causes – and how to tell which one you have
1. Old session left in the browser
How to tell: The error appears on page load for one user or browser, often after signing out elsewhere, deleting the user, or switching Supabase projects, and it stops in a private window.
Fix: When getSession or getUser returns this error, call supabase.auth.signOut() to clear the stored session and send the user to the login page. Clearing the site data in the browser fixes it for you right away.
2. Several clients refreshing at once
How to tell: You create a new Supabase client in many components, or the app runs in several tabs, and the error shows up randomly after the access token expires (about an hour by default).
Fix: Create one browser client and reuse it everywhere (a single module that exports it). The library coordinates refreshes for one client; many separate clients race each other.
3. Next.js server and browser both refresh
How to tell: You use Next.js with server components or route handlers, and the error appears in server logs or after navigation, often with the older auth-helpers package or a hand-rolled cookie setup.
Fix: Use @supabase/ssr and refresh the session in middleware as the Supabase Next.js guide shows, so cookies are updated in one place and passed on to the response. Remove older auth-helpers code.
4. Session from another project or environment
How to tell: It started after you changed the Supabase URL or keys, or you use the same localhost port for two projects, so the browser sends a token the new project never issued.
Fix: Sign out and clear local storage and cookies for that site, then sign in again. Use different ports or storage keys for separate projects locally.
How to fix it
- Clear your browser's site data for the app (or open a private window) and sign in again to confirm the account itself works.
- Search the code for createClient or createBrowserClient. Move it into one file (for example lib/supabase.ts) that exports a single client, and import that everywhere.
- Where the app loads the session (getSession / getUser or onAuthStateChange), check for this error and call supabase.auth.signOut(), then redirect to the login page.
- If you use Next.js with server components, set up @supabase/ssr with the middleware that refreshes the session, as in Supabase's Next.js server-side auth guide, and remove older auth-helpers code.
- If you recently switched Supabase projects or keys, make sure every environment uses the new URL and anon key, and sign out on all devices.
- Sign in, keep the app open across two tabs past a token refresh, and confirm the error no longer appears.
Using Lovable, Bolt or v0?
In Lovable or Bolt, tell the AI: "Users sometimes get 'Invalid Refresh Token: Refresh Token Not Found'. Use one shared Supabase client, and when this auth error happens, sign the user out and redirect to the login page instead of showing a broken page." To fix it on your own device immediately, clear the site data for your app in the browser and sign in again. In the Supabase Dashboard, the Auth logs show when refreshes fail.
Using Cursor, Claude Code or Windsurf?
Ask Cursor or Claude Code to find every createClient / createBrowserClient call and reduce them to one shared browser client, and in Next.js to set up session refresh in middleware with @supabase/ssr following the official guide. Have it add handling for refresh_token_not_found that signs the user out, then test by signing in, waiting for or forcing a token refresh, and opening the app in two tabs.
The “fix” to avoid
Agents often turn off autoRefreshToken or catch the error and keep showing the page as if the user were logged in. Then sessions expire after an hour and every database call fails with permission errors or RLS violations. Others store tokens by hand in localStorage, which creates new race conditions. Let the Supabase client manage the session and sign out cleanly when the refresh token is gone.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My Supabase app throws "AuthApiError: Invalid Refresh Token: Refresh Token Not Found". Check in this order: 1) is more than one Supabase client created (createClient/createBrowserClient in several components)? Replace them with one shared client. 2) In Next.js, are sessions refreshed in middleware with @supabase/ssr following the official guide, with no leftover auth-helpers code or manual cookie handling? 3) Does the app handle this error by calling supabase.auth.signOut() and redirecting to login instead of showing a broken page? 4) Did the Supabase URL or keys change so old sessions are stale? Don't disable autoRefreshToken and don't store tokens manually. Explain the cause and verify by signing in, using two tabs and waiting past a token refresh without the error.
Questions people ask
Is 'Invalid Refresh Token' a security problem?
Usually not. It means a saved session can no longer be refreshed, so the user needs to sign in again. Supabase also detects reuse of refresh tokens and revokes them, which can trigger the same error.
How do I fix it for myself right now?
Clear the site data for your app in the browser (or sign out and in again). That removes the stale session. The code changes stop it from happening to your users.
Why does it happen about an hour after logging in?
That's when the access token expires and the client uses the refresh token. If several clients or the server and browser try to refresh at the same time, one of them gets this error.