Fix guides · Lovable, Bolt, Cursor, Claude Code, Replit ·

Fix Supabase "JWT expired" (PGRST303, 401)

{"code":"PGRST303","details":null,"hint":null,"message":"JWT expired"}

Supabase rejected a request because the access token it carried has expired. Access tokens are short-lived (an hour by default) and the client should refresh them automatically. You see this error when something sends an old token: a server or edge function that stored the token, a client with auto refresh turned off, a tab that slept for hours, or a hard-coded Authorization header.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. The token was saved and reused

How to tell: The code stores session.access_token at login (state, localStorage, a variable) and adds it to fetch headers later. The error starts about an hour after login.

Fix: Read the token from the Supabase client right before each call: const { data } = await supabase.auth.getSession(); then use data.session?.access_token.

2. Auto refresh is off or there are several clients

How to tell: createClient is called with autoRefreshToken: false, or a new client is created in many components or on every render.

Fix: Create one client in a shared file (lib/supabase) with the default auth options and import it everywhere.

3. Server-side code doesn't refresh the session

How to tell: Next.js server components, route handlers or server actions fail with JWT expired while the browser looks logged in.

Fix: Use @supabase/ssr and the middleware/proxy setup from the Supabase SSR guide so the session cookie is refreshed on each request.

4. An Edge Function or webhook gets an old token

How to tell: supabase.functions.invoke or your own fetch to an Edge Function returns 401 after a while, but works right after login.

Fix: Use supabase.functions.invoke from the logged-in client (it sends the current token), or get a fresh token before calling fetch yourself.

5. The device clock is wrong or the tab slept

How to tell: Only one computer has the problem, or it happens after a laptop wakes up from sleep.

Fix: Fix the system time. After wake-up, the client refreshes on the next request; make sure you don't block requests that run before the refresh finishes.

How to fix it

  1. Find which request fails: open the browser Network tab and look for the 401 with JWT expired.
  2. Check where its Authorization header comes from. It should come from the Supabase client, not from a saved variable or localStorage value.
  3. In the browser client, keep autoRefreshToken and persistSession on (the default) and use one shared client instance.
  4. If you call your own API or an Edge Function, get the current token right before the call with supabase.auth.getSession(), not from state saved at login.
  5. With Next.js and @supabase/ssr, make sure the proxy/middleware refreshes the session on every request as in the Supabase SSR guide.
  6. Check the computer's clock: a wrong system time can make fresh tokens look expired.
  7. Log out, log in again and repeat the action to confirm.

Using Lovable, Bolt or v0?

In Lovable or Bolt, paste the error and say: "Stop storing the Supabase access token. Always use the shared Supabase client so it refreshes the session, and get a fresh token with getSession() before calling Edge Functions."

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to search the code for access_token, Authorization and createClient, and report every place where a token is stored or a second client is created. Fix those instead of changing expiry settings.

The “fix” to avoid

Agents sometimes raise the JWT expiry to days, switch to the service_role key, or disable JWT verification on the Edge Function. Those make the error disappear by removing security. Fix the refresh instead.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

Supabase requests fail with 401 {"code":"PGRST303","message":"JWT expired"}. Find where the access token is stored or passed manually (Authorization headers, localStorage, React state, server variables) and replace that with fresh tokens from the Supabase client (supabase.auth.getSession() right before the call). Use one shared browser client with autoRefreshToken and persistSession enabled. If this is Next.js with @supabase/ssr, make sure middleware/proxy refreshes the session on every request as in the Supabase SSR guide. Don't increase the JWT expiry and don't use the service_role key. Show me where the stale token came from.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

How long does a Supabase access token last?

One hour by default. The refresh token keeps the user logged in and gets a new access token automatically when the client is set up correctly.

What's the difference to "Invalid Refresh Token"?

JWT expired means an old access token was sent. Invalid Refresh Token means the refresh itself failed, so the user has to log in again. See our guide on the refresh token error.

Does this mean my users were hacked?

No. It's a normal expiry. Supabase rejects the old token on purpose.

Official documentation

Related errors

Get fixes like this every week