Fix guide · updated 2026-11-15
Supabase "Auth session missing!" error
AuthSessionMissingError: Auth session missing! · session_not_found · PKCE code verifier not found in storage
A user clicks your reset link, types a new password, and gets "Auth session missing!". Or your server logs print AuthSessionMissingError: Auth session missing! for every visitor. Supabase isn't down and your keys are fine. Your code asked supabase-js to act for a logged-in user, and at that moment it had no session to use. Here's where the session went, and the fix for each case.
What the error means
We read where supabase-js raises it (its auth client, GoTrueClient.ts). Most of the time it's a check in your own app, before anything is sent to Supabase: the methods that act for the logged-in user look for a stored session first. With none, updateUser(), refreshSession(), reauthenticate() and the passkey calls fail with this error, and getUser() returns user: null together with it.
It can also start on the server. When the session inside the user's token no longer exists in Supabase's database, Supabase answers session_not_found. supabase-js turns that answer into the same error and deletes the session it had stored. Its own code comment gives the reasons: the user signed out, was deleted, or the session was ended some other way.
So the useful question isn't "why is Supabase broken" but "why is there no session right here". Six situations cover it.
1. Nobody is logged in, and that's normal
On a page anyone can open, getUser() returns this error for a visitor who isn't logged in. That's the expected answer, not a failure. The bug is code that treats it as one: a red toast on the home page, an error screen, a server log line for every visitor. Let it through as "logged out":
import { isAuthSessionMissingError } from '@supabase/supabase-js';
const { data: { user }, error } = await supabase.auth.getUser();
if (error && !isAuthSessionMissingError(error)) {
throw error; // a real problem: network, bad key, server error
}
// user === null means "not logged in": show the logged-out page
2. The reset link didn't log the user in
Clicking the link in a password reset email is what logs the user in. Supabase's docs say the change-password page is for logged-in users, and updateUser({ password }) needs that session. If the link didn't create one, the form fails with "Auth session missing!". There are three usual reasons:
- The link was opened in another browser or on another device. With the PKCE flow, asking for the email saves a secret in the browser that asked, and only that browser can use the link. Request the reset on a laptop, open the email on a phone, and the link fails without a word. PKCE is always on with
@supabase/ssr, the usual Next.js setup. A plaincreateClient()uses the implicit flow by default: the link carries the session itself and works anywhere. - The link was already used or has expired. Email security scanners often open links before people do, and links expire after an hour by default. The full story is in Supabase "Email link is invalid or has expired".
- Your email template links to your own page with a token hash (
/auth/confirm?token_hash=…&type=recovery, as in Supabase's server-side recipe), but the page never callsverifyOtp(). That call is what creates the session.
The link that works on any device is that token-hash link. In Authentication → Email Templates → Reset Password, point it at your own page:
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=recovery">Reset password</a>
On that page, trade the hash for a session, then show the form:
const params = new URLSearchParams(window.location.search);
const { error } = await supabase.auth.verifyOtp({
token_hash: params.get('token_hash'),
type: 'recovery',
});
if (error) {
// used or expired: offer to send a new link
} else {
// logged in now: show the new-password form, which calls updateUser
}
Our email link guide explains why verifyOtp() should run when the user clicks a button, not on page load. Whatever your setup, check for a session before you show the form. A form that can only fail is worse than a clear message:
const { data: { session } } = await supabase.auth.getSession();
if (!session) {
// "This link has expired or was opened on another device." + a button that sends a new one
}
3. Your server can't see the browser's session
On Next.js and other server frameworks, server code finds the session in cookies. createClient() from supabase-js keeps it in the browser's localStorage, which is never sent to your server. So every server-side getUser() says "Auth session missing!", even for a user who is logged in on the page. supabase-js's own PKCE error message gives the fix: use @supabase/ssr on both sides, createBrowserClient() in the browser and createServerClient() with your framework's cookie functions on the server.
Already on @supabase/ssr? Check the cookie functions you pass to createServerClient(). If getAll doesn't return the request's cookies (an empty stub, or the wrong cookie store), the server never sees a session.
4. An Edge Function calls getUser() without the user's token
A Supabase Edge Function has no stored session. It only knows who is calling from the Authorization header on the request. Read that token and pass it in:
const token = req.headers.get('Authorization')?.replace('Bearer ', '');
const { data: { user }, error } = await supabase.auth.getUser(token);
Creating the client with that header (global: { headers: { Authorization: … } }) works too: supabase-js then skips its session check. If the header is missing, the call didn't go through supabase.functions.invoke() with a logged-in user, which adds it for you. More on failing function calls in Edge Function returned a non-2xx status code.
5. The session was ended on the server
A password change on another device, a logout on another device (supabase-js logs out everywhere by default), or a deleted user (deleting test users counts) ends the session on Supabase's side. The next getUser() gets session_not_found, supabase-js turns it into "Auth session missing!" and removes the stored session. Send the user to your login page when that happens. Supabase "Invalid Refresh Token: Refresh Token Not Found" covers these causes and how to handle the sign-out cleanly.
6. A mobile app forgets the session when it restarts
supabase-js keeps the session in localStorage when it can. React Native has no localStorage, so without a storage option the session lives only in memory and is gone each time the app restarts. Give it a real store, as Supabase's Expo example does:
import AsyncStorage from '@react-native-async-storage/async-storage';
export const supabase = createClient(SUPABASE_URL, SUPABASE_KEY, {
auth: { storage: AsyncStorage, autoRefreshToken: true, persistSession: true, detectSessionInUrl: false },
});
If an AI tool built your app
AI builders tend to show every auth error in a toast and to make the reset page a plain form. Paste this into your next prompt:
Treat AuthSessionMissingError from supabase.auth.getUser() as "logged out", not as an error: no toast, no error page (use isAuthSessionMissingError from @supabase/supabase-js). On the reset-password page, call supabase.auth.getSession() first; if there is no session, show "This link has expired or was opened on another device" and a button that sends a new reset email, instead of the password form. Never call updateUser without a session.
Not quite your error?
- Users get logged out at random: Supabase "Invalid Refresh Token: Refresh Token Not Found".
- The reset or confirm link says it's invalid or expired: Supabase "Email link is invalid or has expired".
- The code exchange fails with "invalid flow state, no valid flow state found": Supabase "invalid flow state, no valid flow state found".
- The reset email never arrives: Supabase "Error sending confirmation email".
- The link sends users to localhost: Supabase login redirects to localhost.
Still stuck?
Turn on supabase-js debug logs for a moment (auth: { debug: true } in createClient) and open the reset link again. The console shows whether supabase-js found the link in the address and why it couldn't use it, for example "PKCE code verifier not found in storage". Then open the Auth logs in your Supabase dashboard at that time: the request for that link is there, with its error if it failed.
Other Supabase problems? See Supabase fixes.