Skip to content

What does 'PGRST301 JWT expired' mean?

Short answer

The access token sent with the request is past its exp time, so PostgREST rejects it with 401. Older PostgREST versions report this as PGRST301; current versions use PGRST303 'JWT expired'. Let the Supabase client refresh the session instead of storing or hard-coding a token.

Last updated 2026-11-25 · Reviewed by ProofForge

The exact error

text
{"code":"PGRST301","details":null,"hint":null,"message":"JWT expired"}
{"code":"PGRST303","message":"JWT expired"}   (newer PostgREST)

Why it happens

  • A user's access token expired and the client didn't refresh it (for example a token cached in localStorage, an env var or a server job).
  • You create your own Supabase client per request on the server without passing the current session.
  • The device clock is far off. PostgREST allows about 30 seconds of skew.

How to fix it

  1. Use one Supabase client in the browser with autoRefreshToken on (the default), and read the session from the client instead of saving tokens yourself.
  2. On the server, use the SSR helpers so each request carries the user's refreshed cookies.
  3. Never put a user JWT, or the service_role key, in an env var to dodge expiry.
ts
// browser: one shared client, default auto-refresh
import { createClient } from '@supabase/supabase-js'
export const supabase = createClient(URL, PUBLISHABLE_KEY)

// before a call, get the current (refreshed) session
const { data: { session } } = await supabase.auth.getSession()
if (!session) { /* send the user to sign in */ }

Check it's fixed

Leave the app open past the token lifetime, then make a request. It should succeed without a 401.

Check your live app

A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.

Read-only. No writes or row contents.

FAQ

PGRST301 or PGRST303?

Both are 401 JWT errors. PostgREST now uses PGRST301 for tokens it can't decode and PGRST303 for claim failures such as an expired exp. Older versions returned PGRST301 'JWT expired'.

Does rotating my API keys fix this?

No. The anon or publishable key isn't the expired token. It's the signed-in user's access token.

Is it a security problem?

Not by itself. It's PostgREST correctly refusing an old token. Don't 'fix' it by switching to a privileged key.

Sources

Related

Read as Markdown · Scan methodology