# AuthSessionMissingError: Auth session missing! (Supabase)

Returned by supabase-js when an auth call needs a signed-in user and the client has no session: getUser() with no access token in storage, and updateUser(), setSession() or refreshSession() without one. It is also what you get when the auth server answers session_not_found because the user signed out elsewhere or was deleted, and getUser() then clears the local session. By default it comes back in the error field with status 400, not thrown. Most reports are from server code (Next.js Server Components, Route Handlers, middleware) whose client can't see the browser's auth cookies.

```
AuthSessionMissingError: Auth session missing!
    at node_modules/@supabase/auth-js/dist/main/GoTrueClient.js:2715:59
    at SupabaseAuthClient._useSession (node_modules/@supabase/auth-js/dist/main/GoTrueClient.js:2502:26)
    at async SupabaseAuthClient._getUser (node_modules/@supabase/auth-js/dist/main/GoTrueClient.js:2707:20)
    at async SupabaseAuthClient.getUser (node_modules/@supabase/auth-js/dist/main/GoTrueClient.js:2691:22) {
  __isAuthError: true,
  status: 400,
  code: undefined
}
```

## Quick fix

Treat it as "not signed in", not as a crash: check isAuthSessionMissingError(error) and redirect to sign in or render the signed-out page. If the user is signed in and you still get it on the server, the server client isn't reading the auth cookies: create it with createServerClient from @supabase/ssr and pass cookies getAll and setAll, and refresh the session in middleware (proxy) so Server Components get a valid cookie. To check who is signed in on the server, Supabase now recommends getClaims(), which verifies the token and returns data: null with no error when there is no session.

1. Check what you got: error.name is AuthSessionMissingError (or isAuthSessionMissingError(error) is true) and data.user is null. Nothing broke; the client has no session.
2. In the browser: was anyone signed in? A page that loads before sign-in, or after signOut() in another tab, gets this on every getUser().
3. On the server: log the request's cookie names. No sb-<project-ref>-auth-token cookie means the browser never sent it (a fetch from another origin without credentials, or a cookie set for a different domain).
4. If the cookie is there, the client is wrong: a plain createClient() on the server has no access to cookies. Use createServerClient from @supabase/ssr with cookies.getAll and cookies.setAll.
5. Add the middleware (proxy in Next.js 16) from Supabase's Next.js guide that calls getClaims() on each request, so expired tokens are refreshed and written back as cookies. Server Components can't set cookies themselves.
6. Branch on the error instead of throwing it, so a signed-out visitor sees the sign-in page rather than an error page.

```ts
import { isAuthSessionMissingError } from '@supabase/supabase-js';

const { data, error } = await supabase.auth.getUser();
if (isAuthSessionMissingError(error)) {
  // No session: a signed-out visitor, or a server client that can't see the cookies
  redirect('/login');
}
if (error) throw error; // anything else is a real failure: report it
const user = data.user;

// On the server, getClaims() says "nobody" without an error:
// const { data: claims } = await supabase.auth.getClaims(); // claims is null when signed out
```

## Why it happens

### Nobody is signed in

getUser() on a page a signed-out visitor can open returns this every time. It is the normal answer for "no user", so code that throws any error from getUser() turns every anonymous visit into a 500.

### Server client without cookies

In Next.js, SvelteKit or Remix the session lives in cookies. A client made with createClient() on the server has no storage and no session, so getUser() reports it missing even for a signed-in user. createServerClient from @supabase/ssr with getAll and setAll fixes it.

### No middleware refreshing the session

Access tokens expire. Server Components can read cookies but not write them, so without the middleware (proxy) that refreshes the token on each request, a long-lived tab ends up with no usable session on the server.

### The cookie never arrived

A fetch to your API from another origin without credentials: include, an API on a different domain than the cookie, or a mobile or server-to-server call that sends no cookie or Authorization header.

### Signed out somewhere else

The access token is still in storage but the auth server answers session_not_found: the user signed out on another device, an admin deleted the user or ended the session. supabase-js maps that to AuthSessionMissingError and getUser() clears the local session.

## Other fixes

- Calling updateUser() or setSession() before the session has loaded gives the same error. In the browser, wait for onAuthStateChange to report INITIAL_SESSION before calling them.
- Passing a JWT yourself (getUser(jwt)) skips the stored session, so an API that receives a bearer token can check it without cookies.
- Don't trust getSession() on the server to decide who someone is: it reads the cookie without checking it. Supabase recommends getClaims() there.
- Report the errors that are not AuthSessionMissingError yourself: supabase-js returns auth errors instead of throwing them, so a global error handler never sees them.

## Same error, other wording

- `Auth session missing!`
- `AuthSessionMissingError`
- `{"name":"AuthSessionMissingError","message":"Auth session missing!","status":400}`

## Sources

- [Supabase docs: server-side auth for Next.js (createServerClient, cookies, middleware, getClaims)](https://supabase.com/docs/guides/auth/server-side/nextjs)
- [Supabase docs: auth.getUser()](https://supabase.com/docs/reference/javascript/auth-getuser)
- [supabase-js source: AuthSessionMissingError and isAuthSessionMissingError](https://github.com/supabase/supabase-js/blob/master/packages/core/auth-js/src/lib/errors.ts)
- [supabase-js source: getUser() returning the error when there is no session](https://github.com/supabase/supabase-js/blob/master/packages/core/auth-js/src/GoTrueClient.ts)
- [supabase-js source: session_not_found mapped to AuthSessionMissingError](https://github.com/supabase/supabase-js/blob/master/packages/core/auth-js/src/lib/fetch.ts)

---

supabase-js returns this in the error field instead of throwing it, so unless your code throws it or reports it Runheed doesn't record this one. Runheed records the exceptions a running app throws and serves them to coding agents over MCP: https://runheed.com/?ref=agent-md

Human-readable version: https://runheed.com/errors/supabase-auth-session-missing
