Supabase error: JWT expired
AuthApiError: JWT expired
{ code: "PGRST301", message: "JWT expired" }In one sentence: The user's login token ran out and wasn't refreshed, so Supabase rejects the request until the session is renewed.
What it means
Supabase access tokens expire after about an hour. The Supabase client normally refreshes them in the background, but if your code stores the token itself, or the server never gets the refreshed cookie, requests start failing with this error.
In Next.js this usually shows up on server components or API routes, because the auth cookie isn't refreshed on the server.
Common causes
- The access token was saved somewhere (localStorage, state, a header) and reused after it expired.
- A Next.js app without the Supabase middleware that refreshes the session cookie on each request.
- Several Supabase clients created in different places, so one has a stale session.
- The device clock is far off, so tokens look expired early.
How to fix it
- Let the Supabase client manage the session. Don't copy the access token into your own variables or headers.
- In Next.js, use `@supabase/ssr` and add its middleware so the session is refreshed on every request.
- Create one shared client (for example in `lib/supabase`) and import it everywhere.
- If a request still fails, call `supabase.auth.refreshSession()` once, and send the user to log in again if that fails.
Before
const token = localStorage.getItem("token");
await fetch(url, { headers: { Authorization: `Bearer ${token}` } });After
const { data: { session } } = await supabase.auth.getSession();
await fetch(url, { headers: { Authorization: `Bearer ${session?.access_token}` } });Tried this and it's still broken? Paste your exact error for a free explanation of your specific case.
Prompt to paste into your AI tool
Supabase returns 'JWT expired'. Find anywhere the access token is stored or reused manually and switch to the Supabase client's session. If this is Next.js, set up @supabase/ssr with middleware that refreshes the session, and use a single shared client. Don't change unrelated code.Still stuck?
Paste your exact error and code. Get a plain-English explanation free, or the full fix for $5.
Hitting errors every day? Builder is $15/mo for 100 fixes per month. Compare plans
Related errors
- Error: Dynamic server usage: Route couldn't be rendered statically because it used cookies
- Module not found: Can't resolve 'fs'
- Next.js: params should be awaited before using its properties
- Error: supabaseUrl is required
Weekly: the errors breaking vibe-coded apps and how to fix them. Free.
No spam. Unsubscribe anytime.