Skip to content
>_VibeUnstuck

Invalid Refresh Token: Refresh Token Not Found

Last verified:

The fix

Supabase rejected the refresh token in the cookie. It was already rotated or revoked, or the new token was never written back onto the response.

  1. 1

    Stop retrying the dead token

    When the message is Refresh Token Not Found, another refresh with the same cookie will fail again and can revoke the session family. Do not loop getSession() or refreshSession() in the client. Sign the user out of this browser and send them through sign-in once. If signOut itself returns this error, the token is already gone. Clear the site cookies and sign in.

  2. 2

    Refresh once, in proxy, with one client

    Use createBrowserClient from @supabase/ssr in client components and createServerClient on the server. Do not also construct createClient from @supabase/supabase-js in the browser for the same project. On Next.js 16, export proxy from proxy.ts. On older Next.js, export middleware from middleware.ts. Call getUser(), write every cookie from setAll onto the response, and return that response. Do not call getUser() again in an API route on the same request after proxy already refreshed.

    import { createServerClient } from '@supabase/ssr'
    import { NextResponse } from 'next/server'
    
    export async function proxy(request) {
      let supabaseResponse = NextResponse.next({ request })
      const supabase = createServerClient(
        process.env.NEXT_PUBLIC_SUPABASE_URL,
        process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
        {
          cookies: {
            getAll() {
              return request.cookies.getAll()
            },
            setAll(cookiesToSet) {
              cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))
              supabaseResponse = NextResponse.next({ request })
              cookiesToSet.forEach(({ name, value, options }) =>
                supabaseResponse.cookies.set(name, value, options),
              )
            },
          },
        },
      )
      await supabase.auth.getUser()
      return supabaseResponse
    }
  3. 3

    Sign out of this session only

    A button that calls signOut() with no arguments revokes every session. Use local scope so other devices keep their refresh tokens. After the call, the sb- auth cookies for this host should be gone. If a second tab still has the old cookie, that tab will throw this error once. Reload it and sign in. Do not switch the server to the service role key to skip the refresh.

    await supabase.auth.signOut({ scope: 'local' })
  4. 4

    Clear a stuck cookie once, then upgrade the package

    In the browser devtools, delete cookies for localhost and the deployed host whose names start with sb-. Sign in again. If the project is on @supabase/ssr older than 0.8.1, upgrade it so the server client does not refresh in the background before your getUser() call. On a self-hosted Auth server, set GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL to a few seconds. Do not disable refresh-token reuse detection.

Why it happens

The browser or the server log shows AuthApiError: Invalid Refresh Token: Refresh Token Not Found. Auth is saying the refresh token on this request is not a live token for a session.

Supabase's session guide: a refresh token is used once, with two exceptions. It can be presented again inside a reuse interval. The docs say that interval defaults to 10 seconds and they do not recommend changing it. And if you present the parent of the token that is current now, the server returns the current pair instead of ending the session. That second case is a lost response: the server rotated the token, and the browser never stored the new Set-Cookie. Outside those two cases, reuse revokes the whole session.

The cookie is stale when something else already rotated or revoked it. Two clients do that with one token. A browser tab and the server proxy both refresh, or createClient from @supabase/supabase-js (local storage) sits next to createBrowserClient from @supabase/ssr (cookies). @supabase/ssr also used to refresh in the background while your own getUser() refreshed. The package maintainers fixed that in @supabase/ssr 0.8.1 by skipping auto-initialize on the server client. Upgrade if you are older than that.

The other miss in generated Next.js apps is the proxy. getUser() refreshes when the access token is near expiry, and the new refresh token has to be copied onto the outgoing response with setAll. Drop that response and the browser keeps the old token. The next call is Refresh Token Not Found. On Next.js 16 the refresh is proxy.ts exporting proxy. On older Next.js it is middleware.ts exporting middleware. A missing session with no refresh-token error is the page for auth session missing after refresh.

supabase.auth.signOut() with no scope defaults to global. Supabase's server-side guide says that revokes the refresh token for every session that user has, including other tabs and a server cookie that still holds the old token. Those tabs then throw this error. End this session with { scope: 'local' }.

Self-hosted GoTrue can have the reuse interval off. The @supabase/ssr maintainers say to set GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL to a few seconds on a self-hosted project. Hosted projects already have a short window. Do not turn reuse detection off to hide a dead cookie.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Auth session missing after refresh. Auth session missing: sign-in worked in the browser, but Next.js cannot see the Supabase cookie. Use the @supabase/ssr server client and refresh.

Prompt to paste back into your AI tool

Paste this above the error.

Supabase throws AuthApiError: Invalid Refresh Token: Refresh Token Not Found. It happens on <where: server log, browser, or both>.

Do not disable refresh-token reuse detection. Do not switch the server to the service role key. Do not call refreshSession in a loop. Do not create a second Supabase client with @supabase/supabase-js next to @supabase/ssr.

1. Show me every createClient / createBrowserClient / createServerClient in this app.
2. Refresh the session in one place: proxy.ts exporting proxy on Next.js 16, or middleware.ts exporting middleware on older Next. Call getUser() and return the response that setAll wrote cookies onto.
3. Change sign-out to supabase.auth.signOut({ scope: 'local' }).
4. Tell me to delete the sb- cookies once and sign in again. Do not rewrite unrelated pages.

Common questions

+getSession() still shows a user and getUser() throws this. Which one do I trust?

getUser(). getSession() reads the cookie and does not prove the refresh token is still valid. When getUser() returns Refresh Token Not Found, that cookie is dead. Clear it and sign in again.

+Signing out on my laptop broke the phone session. Why?

signOut() with no scope is global. It revokes every refresh token for that user, so the other device sends a token Auth has already revoked. Use signOut({ scope: 'local' }) when you only mean this browser.

Related errors