AuthApiError: Invalid Refresh Token: Refresh Token Not Found means your app tried to refresh a Supabase session that no longer exists, so the user gets signed out, often at random and usually on a second device or the next morning. The session was revoked (most often by a global sign-out elsewhere), lost a race between two clients refreshing the same single-use token, or comes from a stale cookie.
Quick fix
Change your logout button to supabase.auth.signOut({ scope: 'local' }), make sure your app creates only one Supabase client (and, with @supabase/ssr, upgrade to 0.8.1 or later), and send people to the login page on the SIGNED_OUT event instead of letting pages fail. The sections below match each cause to its fix.
What you see
Your Lovable, Bolt, v0 or Cursor app uses Supabase Auth. Users log in fine, but some of them get thrown back to the login page at random (often the next morning, or after logging in on their phone), and your browser console or server logs show:
AuthApiError: Invalid Refresh Token: Refresh Token Not Found
status: 400,
code: 'refresh_token_not_found'
In the Network tab the failing request is POST /auth/v1/token?grant_type=refresh_token. Supabase’s error code list describes refresh_token_not_found as: “Session containing the refresh token not found.” A close relative, refresh_token_already_used, means the token “has been revoked and falls outside the refresh token reuse interval.”
Why it happens
Supabase’s sessions docs explain the model: access tokens are short-lived (usually 5 minutes to 1 hour), and refresh tokens “never expire but can only be used once”. supabase-js swaps the refresh token for a new pair shortly before the access token expires. So this error means the client presented a refresh token whose session no longer exists. Here are the usual reasons, each with its fix.
Cause 1: the user signed out somewhere else (global sign-out)
Supabase’s sign-out docs say JavaScript defaults to the global scope, and that with it, “calling signOut() on one device revokes the refresh tokens for every session that user has, including other devices and browsers. Those other sessions fail with AuthApiError: Invalid Refresh Token: Refresh Token Not Found the next time they try to refresh, even though no one signed out on that device.” Most generated logout buttons call plain signOut().
If logging out on one device shouldn’t log the user out everywhere, say so explicitly:
// only this browser/device
await supabase.auth.signOut({ scope: 'local' });
// a separate "Log out everywhere" button, if you want one
await supabase.auth.signOut({ scope: 'global' });
Global sign-out is the right call after a password reset or a suspected stolen account. Just make it a deliberate choice, not an accident of the default.
Cause 2: two clients refreshed the same token at once
Because refresh tokens are single use, a race loses. In supabase/ssr #68 (users logged out every day in a Next.js app), a Supabase maintainer explains that a background refresh in the server client raced the middleware’s own getUser(), “Since refresh tokens are single-use, whichever side ‘lost’ the race would get Invalid Refresh Token: Refresh Token Not Found.” That bug was fixed in @supabase/ssr 0.8.1. Later reports in the same thread trace back to “concurrent refreshes (a browser tab and SSR middleware both racing to refresh at once)”. One commenter found their middleware and a /api/auth/user route were both refreshing the token on page load, and the race went away once only one of them did.
For server-rendered apps (Next.js, v0, Cursor projects using @supabase/ssr):
- Upgrade:
npm install @supabase/ssr@latest @supabase/supabase-js@latest(the middleware race was fixed in 0.8.1). - Create a new server client per request, and let middleware be the one place that refreshes the session for page requests.
- Don’t refresh in both middleware and an API route for the same page load. That’s the overlap described in #68.
For single-page apps (most Lovable and Bolt projects), create one Supabase client in a shared module and import it everywhere:
// src/lib/supabase.ts: the only place createClient is called
import { createClient } from '@supabase/supabase-js';
export const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY, // the public key, never service_role
);
If supabase-js logs “Multiple GoTrueClient instances detected in the same browser context”, you have more than one; its source warns this “may produce undefined behavior when used concurrently under the same storage key.”
Cause 3: reuse detection ended the session (refresh_token_already_used)
The sessions docs allow reuse of a refresh token within a 10-second interval (for SSR handing a token to the browser, for example). Outside the exceptions, “the whole session is regarded as terminated and all refresh tokens belonging to it are marked as revoked.” That’s the refresh_token_already_used variant, and the next refresh with any token from that session fails.
Hosted projects already have the 10-second interval; Supabase’s docs advise against changing it, so fix the race (cause 2) instead. If you self-host Supabase, the maintainer in #68 says self-hosted instances default the grace window to off and suggests setting GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL to a few seconds.
Cause 4: the session ended on purpose
Per the sessions docs, a session also ends when the user changes their password, hits an inactivity timeout or the time-box you configured, or signs in elsewhere with Single session per user enabled. The next refresh from the old device then fails with this error.
That’s expected behavior, not a bug. If users complain, check those settings under Auth in the Supabase dashboard, and make sure the app handles it cleanly:
supabase.auth.onAuthStateChange((event) => {
if (event === 'SIGNED_OUT') {
// clear any cached user data in your app state here
window.location.assign('/login?reason=session-ended');
}
});
The supabase-js source shows that when a refresh is rejected and the access token has already expired, the client removes the stored session and fires SIGNED_OUT. Show “Your session ended, please log in again” on the login page when reason=session-ended is present, instead of a raw error.
Cause 5: a stale cookie or stored session (a login loop)
In supabase/supabase #27283 a production-only login loop came from leftover sb-<project-ref>-auth-token cookies set on an older domain (app.domain.com) after moving cookies to .domain.com. Sign-out cleared the new cookie but not the old one, so a dead token kept coming back.
If one browser is stuck in a loop:
- Call
await supabase.auth.signOut({ scope: 'local' })once. Local sign-out removes the stored session first and firesSIGNED_OUT, even if the server call fails. - If you changed domains or cookie settings, look in DevTools > Application > Cookies for
sb-...-auth-tokencookies on the old domain and delete them, as in #27283.
Look-alike: a signed-out visitor hits an auth.uid() query
supabase/ssr #112 reports the same error when a visitor who isn’t logged in triggers a query behind an auth.uid() policy. The maintainer’s workaround is to check supabase.auth.getUser() first and handle the no-user case:
const { data: { user } } = await supabase.auth.getUser();
if (!user) {
// show the signed-out view; don't run queries that need auth.uid()
}
A prompt for your AI builder: “Users get ‘Invalid Refresh Token: Refresh Token Not Found’. Make the logout button call supabase.auth.signOut({ scope: ‘local’ }). Make sure there is exactly one Supabase client instance in the app. Add an onAuthStateChange listener that redirects to /login?reason=session-ended on SIGNED_OUT and shows a friendly message there.”
Check it worked
- Log in on two browsers (or a normal and a private window). Log out in one. The other should stay logged in.
- Leave a tab open past the access token expiry (the JWT expiry set in your Auth settings) and use the app: no error, no surprise logout.
- In a server-rendered app, watch your logs while clicking around quickly.
refresh_token_not_foundshould no longer appear. - Force a dead session (log out everywhere from another device): the remaining tab should land on your login page with the friendly message, not a broken screen.
Random logouts erode trust fast, and they usually come with other auth gaps. If sign-up or magic links send people to localhost, see Supabase auth redirects to localhost. If new users can’t log in until they click a link, see Supabase “Email not confirmed”. And before launch, make sure no table is open to anyone: Supabase “RLS Disabled in Public”. For someone to review your whole auth flow (sessions, redirects, Row Level Security, sign-out), get a written pre-launch audit.
FAQ
What does "Invalid Refresh Token: Refresh Token Not Found" mean?
Supabase could not find the session that refresh token belonged to (error code refresh_token_not_found). The session was ended, revoked or never existed on that project, so the token cannot be swapped for a new access token.
Why are my users logged out on other devices when they log out on one?
In JavaScript, supabase.auth.signOut() uses the global scope by default, which revokes the refresh tokens of every session the user has. Other devices then fail with this error on their next refresh. Use signOut({ scope: "local" }) to log out only the current device.
Do Supabase refresh tokens expire?
Supabase's docs say refresh tokens never expire, but each one can only be used once. Sessions can still end because of sign-out, a password change, an inactivity timeout or time-box you configured, or Single session per user.
Is it safe to ignore this error?
The error itself is not a security problem: supabase-js removes the dead session and fires SIGNED_OUT. What needs fixing is the cause (an accidental global sign-out or a refresh race) and what the user sees: send them to the login page with a clear message instead of a broken screen.