Common errors · Supabase Auth (Lovable, Bolt, Next.js, any supabase-js v2 client)
Supabase Auth session missing: where the session got lost
Cause The recovery code was never exchanged for a session, or server code uses a client that cannot read the browser cookies.
Fix Exchange the code before updating the password, and build server clients from the request cookies with @supabase/ssr.
Have it fixed for you, 290 EURSee the fix step by step
supabase-js throws this when a call needs a signed-in user (getUser, updateUser, signOut) and the client holds no session. In generated apps it shows up most on the reset password page and in server code: the user did click the link, but the session never reached the client that makes the call.
Where it breaks
Which case is yours?
- Reset password page: updateUser({ password }) runs before the client has read the recovery link. With the PKCE flow the link carries ?code= and nothing creates the session until that code is exchanged.
- Server side (Next.js route handlers, server components, server actions): a plain createClient() has no access to the browser cookies, so on the server every user looks signed out.
- The email link points to another origin (localhost, a preview URL) because that URL is missing from the allowed redirect URLs: the session is created there, not on your production domain.
- getUser() on a page that visitors open while signed out: the error is the normal answer, but the app treats it as a crash instead of a signed-out state.
The fix, step by step
- On the reset password page, wait for the recovery session before showing the form. With PKCE, exchange the code from the URL first.
const code = new URLSearchParams(location.search).get("code"); if (code) await supabase.auth.exchangeCodeForSession(code); supabase.auth.onAuthStateChange((event) => { if (event === "PASSWORD_RECOVERY") setReady(true); }); - Only then update the password, and stop on the error instead of assuming success.
const { error } = await supabase.auth.updateUser({ password }); if (error) throw error; - In server code, build the client from the request cookies with @supabase/ssr, never with the browser client.
import { createServerClient } from "@supabase/ssr"; import { cookies } from "next/headers"; const store = await cookies(); const supabase = createServerClient(URL, ANON_KEY, { cookies: { getAll: () => store.getAll(), setAll: (list) => list.forEach(({ name, value, options }) => store.set(name, value, options)), }, }); - In the Supabase dashboard, Authentication, URL Configuration: set the Site URL to your production domain and add your reset page (for example https://yourapp.com/reset-password) to the redirect URLs.
- Where a signed-out visitor is a normal case, read the session first and branch on it instead of calling getUser blindly.
const { data: { session } } = await supabase.auth.getSession(); if (!session) return showSignIn();
How to check it is fixed
Request a reset email for a test account, open the link in a private window on the production domain, set a new password: no error, and signing in with the new password works. A signed-out visitor sees the sign-in screen, not an error.
Delivery example for this error
- await supabase.auth.updateUser({ password })+ await supabase.auth+ .exchangeCodeForSession(code);- Root cause: The recovery code was never exchanged for a session, or server code uses a client that cannot read the browser cookies.
- Change made: Exchange the code before updating the password, and build server clients from the request cookies with @supabase/ssr.
- Request a reset email for a test account, open the link in a private window on the production domain, set a new password: no error, and signing in with the new password works.
- A signed-out visitor sees the sign-in screen, not an error.
Illustrative: the real diff is written against your repository. Full sample report
Still stuck on your own code?
Send the repository and the exact error. Fix: 290 EUR all taxes included, delivered within 72 hours, refunded if not resolved.
Not sure it is this error? Ask for a free written diagnosis, no card needed.