# What does 'AuthSessionMissingError: Auth session missing!' mean?

**Short answer:** 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

```text
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

1. In the browser, treat 'no session' as signed-out and redirect instead of throwing.
2. On the server, create the client with `@supabase/ssr` and the request's cookies.
3. In reset and magic-link flows, call `exchangeCodeForSession(code)` before `updateUser()`.

```ts
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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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.

## Sources

- [Supabase JS: getUser()](https://supabase.com/docs/reference/javascript/auth-getuser)
- [Supabase: User sessions](https://supabase.com/docs/guides/auth/sessions)

## Related

- [Fix 'PGRST301 JWT expired' / PGRST303 in Supabase](/errors/pgrst301-jwt-expired)
- [Fix: service_role key exposed](/fix/service-role-key-exposed)
- [Fix: admin route exposed](/fix/admin-route-exposed)
- [Security check for Lovable apps](/check/lovable)
- [All errors](/errors)
