What does 'AuthSessionMissingError: Auth session missing!' mean?
Supabase-js was asked for the current user (getUser(), updateUser(), signOut()) but has no session. Either nobody is signed in, the session hasn't loaded yet, or server code created a client without the user's auth cookies. Wait for the session or redirect to sign-in. On the server, use the SSR client so cookies are read.
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
AuthSessionMissingError: Auth session missing!
(status 400, name 'AuthSessionMissingError')Why it happens
- Code runs on page load before the stored session is restored.
- Server-side (Next.js route, middleware) client created with only the URL and key, so it has no cookies.
- Sign-in happened on a different domain or subdomain, so cookies don't carry over.
- Password-reset or magic-link flow opened without exchanging the code for a session first.
How to fix it
- In the browser, treat 'no session' as signed-out and redirect instead of throwing.
- On the server, create the client with
@supabase/ssrand the request's cookies. - In reset and magic-link flows, call
exchangeCodeForSession(code)beforeupdateUser().
const { data: { user }, error } = await supabase.auth.getUser()
if (!user) {
// signed out: send to /login instead of crashing
return redirect('/login')
}Check it's fixed
Sign out, then load a protected page. You're redirected without errors. Signed in, getUser() returns your user on both client and server.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
getSession() or getUser() on the server?
Use getUser() (it verifies the token with Supabase Auth) for authorization decisions. Don't trust an unverified session object from cookies.
Is this a security issue?
No, it's the library refusing to act without a user. The risk is 'fixing' it by switching to a service_role client.
Why does it only happen after deploy?
Cookie domain and SameSite settings, or a missing site URL / redirect URL in Supabase Auth settings.