App Finishers

Fix guide · updated 2026-11-16

Supabase "JWT expired" (PGRST303)

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

Requests to your Supabase tables fail with "JWT expired", code PGRST303, HTTP 401, often about an hour after the user logged in. Storage says the same thing as "exp" claim timestamp check failed, and Auth as token has invalid claims: token is expired. We reproduced all three with Supabase's real Auth, Data API and Storage servers and the real supabase-js client (2.119, November 2026). The surprise: supabase-js doesn't send an expired token by itself. Something else in the app does.

What the error means

When a user is signed in, each request carries their access token, a JWT. It has an expiry time, one hour after it was issued unless you changed that setting. Past it, Supabase refuses the token:

Nothing is wrong with the user's account. The session also holds a refresh token, and trading it for a new access token is the normal way out.

Why supabase-js usually doesn't hit it

Before each request, supabase-js checks the session it keeps. If the access token runs out within the next 90 seconds, it refreshes first, then sends the request with the new token. In our test, a session that had expired 10 minutes earlier still worked with the background refresh switched off, which is what supabase-js does in a hidden browser tab: it called the refresh endpoint, then the table. supabase.functions.invoke() did the same.

When the refresh fails, for example because the user signed out on every device, supabase-js doesn't send the expired token either. It drops the session, fires SIGNED_OUT, and sends the request with your public key instead. In our test that gave an empty list, no error, and only a console warning: "Invalid Refresh Token: Refresh Token Not Found".

So "JWT expired" means the token didn't come from supabase-js's own session handling. These are the causes we reproduced.

Cause 1: a token saved and sent by hand

The app keeps a copy of the access token from login and puts it on requests itself. supabase-js refreshes its session, but nobody updates the copy. An hour later, every request with it fails. In our test, each of these sent the expired token:

The same goes for a fetch() with a token kept in React state, a variable, your own localStorage key or a database row, and for a token pasted into Postman, n8n, Make, a cron job or a .env file: it works for an hour, then stops.

Cause 2: the device clock is behind

supabase-js decides whether the token has expired with the device's own clock. With the clock 2 hours behind, it kept sending a token the server had considered expired for 10 minutes, didn't try to refresh it, and got "JWT expired". The same account works on other devices. With the clock 2 hours ahead, nothing failed, but supabase-js refreshed the session before every single request.

Cause 3: server code passing the caller's token along

An Edge Function or API route that takes the user's token from the request and uses it is only as fresh as what the browser sent. If the browser sent a saved token (cause 1), supabase.auth.getUser(token) answers 403 bad_jwt "token is expired", and a client built with that header gets "JWT expired" from your tables. With JWT verification on, an Edge Function stops the request before your code runs: see Supabase Edge Function "Missing authorization header" (401), which covers "Invalid JWT".

The one-minute check

Find out which token the failing request carried. In the browser's developer tools, open the Network tab, click the failing request, and copy its Authorization request header, the part after "Bearer ". Then, in the console:

const t = 'paste the token here';
const { exp } = JSON.parse(atob(t.split('.')[1].replace(/-/g, '+').replace(/_/g, '/')));
console.log(Math.round(Date.now() / 1000 - exp), 'seconds past expiry, by this device clock');

Decode tokens in your own console, not on a website: until it expires, a token works like a password.

Fix 1: let supabase-js add the token

In browser code, create one client with your project URL and public key, and don't set Authorization yourself: no global.headers.Authorization, no headers on functions.invoke(). supabase-js then sends the current token and refreshes it when needed. In our test, a client holding a session that had expired 10 minutes earlier refreshed it and got the rows; with the header set, the same request failed.

export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

const { data, error } = await supabase.from('todos').select('title');
const res = await supabase.functions.invoke('send-invoice', { body: { id } });

Fix 2: when you need the token, read it at call time

For a fetch() to your own API or to another service, get the token from supabase-js right before the call, every time. getSession() refreshes an expiring session first: in our test, a session expired for 10 minutes came back with a token good for another hour.

const { data: { session } } = await supabase.auth.getSession();
const res = await fetch('/api/report', {
  headers: { Authorization: `Bearer ${session?.access_token}` },
});

Don't keep the token in state, context or a variable for later.

Fix 3: jobs that run later keep the refresh token

A worker or scheduled job that acts for a user later can't use a saved access token. Save the refresh token, give both to setSession(), and supabase-js refreshes before the first request. In our test, setSession() with an expired access token and a valid refresh token refreshed first, then read the user's rows. Each refresh token works only once, so save the new session it returns:

const { data, error } = await supabase.auth.setSession({ access_token, refresh_token });
// save data.session.refresh_token for the next run

A job that doesn't need to act as one user can use the service role key instead, on the server only. Never put that key in browser code: it bypasses every security rule in your database.

Fix 4: a device with the wrong clock

If only one user or one device gets the error, have them turn on automatic date and time. Nothing in your code needs to change.

If an AI tool built your app

Give your AI tool this prompt:

My Supabase requests fail with "JWT expired" (PGRST303) about an hour after login. Find every place where the code sets an Authorization header or keeps a user's access token itself: createClient with global.headers.Authorization, the accessToken option, functions.invoke with headers, fetch calls with a Bearer token, and tokens saved in state, context, localStorage or the database. Remove the hand-made headers so supabase-js adds the current token itself, and where a token is really needed, read it with supabase.auth.getSession() right before the call. Keep a single Supabase client for the whole app. Show me each change before making it.

Not quite your error?

Still stuck?

Decode the failing token as above and also print its iat, the time it was issued. If it's older than the session your app is showing, the request used a copy saved at that time: find where your code stored it.

Other Supabase problems? See Supabase fixes.