Supabase error token_expired (token_expired) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Refresh the session with supabase.auth.refreshSession() before authed calls. If that does not apply, subscribe to onAuthStateChange and react to TOKEN_REFRESHED / SIGNED_OUT — the full checklist is below.
Error code: token_expired
Official name: token_expired
Service: Supabase
JWT expired.
const { data: { session }, error } = await supabase.auth.refreshSession()
if (error?.code === 'token_expired') {
// refresh token itself is gone - force re-login
await supabase.auth.signOut()
}
A failed refresh with token_expired usually means the refresh token was also revoked; re-authenticate the user.
Attach the auth state listener so expired sessions trigger a refresh or re-login automatically.
supabase.auth.onAuthStateChange((event) => {
if (event === 'TOKEN_REFRESHED') {
console.log('session refreshed')
}
if (event === 'SIGNED_OUT') {
redirectToLogin()
}
})
Most often this happens when access token older than the default 1-hour TTL, or when client clock skew beyond the allowed leeway.
Refresh the session with supabase.auth.refreshSession() before authed calls.
This page documents fixes for: supabase-js.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official Supabase documentation linked below and adds practical troubleshooting guidance on top.