Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Supabase says Auth session missing when a user resets a password in Next.js

ErrorAuthSessionMissingError: Auth session missing!

Short answer

The error means your code called Supabase without a signed-in session. On a reset page this usually happens because the default email link puts the session in the URL fragment, which a server cannot read. Send the link to a route that calls verifyOtp with token_hash, and make sure the session cookie is refreshed on every request.

  • Applies to Next.js 15, Next.js 16, @supabase/supabase-js 2, @supabase/ssr
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log what the server client sees on the reset page, before calling updateUser. If user is null, no session cookie reached the server.

    const { data, error } = await supabase.auth.getUser()
    console.log(data.user, error?.name)
  2. 2Match what you see, then jump to its fix

    1. 1The page opens from the email link, but a Server Component or Server Action sees no userThe reset email uses the default link, so the server never gets the sessionFix
    2. 2Token has expired or is invalid, even though the link is brand newAn email scanner opened the link firstFix
    3. 3Signed-in calls work for a while, then the server stops seeing the userThe session cookie is not refreshed on each requestFix
    4. 4The call is made from server code or a client created without the request cookiesupdateUser runs on a client that holds no logged-in userFix

What does the error look like?

  • AuthSessionMissingError: Auth session missing!
  • Token has expired or is invalid

Cause 1 of 4

The reset email uses the default link, so the server never gets the session

1Check

The email template docs say the default confirmation link returns the session in the URL fragment, and the server cannot read a fragment. Look at your Reset Password template for the variable it uses.

# Dashboard > Authentication > Email Templates > Reset Password
# look for {{ .ConfirmationURL }}

2Fix

Change the template to link to your own route with the token hash, then verify it on the server. The Supabase password guide shows this exact template and a Next.js route handler.

<!-- Reset Password template -->
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=recovery&next=/account/update-password">Reset password</a>

// app/auth/confirm/route.ts (core of the handler)
const { error } = await supabase.auth.verifyOtp({ type, token_hash })
if (!error) {
  return NextResponse.redirect(redirectTo)
}

3Verify

Request a new reset email, click it, and confirm the update-password page now shows a user.

# after clicking the link, getUser() returns the user instead of AuthSessionMissingError

Confirmed by supabase.com

Did this fix it?

Cause 2 of 4

An email scanner opened the link first

1Check

The email template docs warn that some email providers prefetch links, which can use up a ConfirmationURL before the person clicks. No session is created for the real click.

# Compare the time the link was sent with the time the error was logged

2Fix

Use the token_hash link from the first cause, or an email one-time code, so a prefetch cannot consume the token.

<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=recovery&next=/account/update-password">Reset password</a>

3Verify

Send yourself a reset email through the affected provider and click it once.

# the update-password page loads signed in

Confirmed by supabase.com

Did this fix it?

Cause 3 of 4

The session cookie is not refreshed on each request

1Check

With @supabase/ssr, a proxy refreshes the session and writes the cookies. The Supabase Next.js guide says the file is proxy.ts in Next.js 16, and that on Next.js 15 and earlier a proxy.ts file is never called, so sessions never refresh.

ls middleware.ts proxy.ts src/middleware.ts src/proxy.ts 2>/dev/null

2Fix

Name the file for your Next.js version (middleware.ts up to 15, proxy.ts from 16), and return the response object the setAll callback built.

npx next --version
# Next.js 15 or older: middleware.ts
# Next.js 16 or newer: proxy.ts

3Verify

Wait past the access token lifetime, reload the page and call getUser again.

# getUser() still returns the user

Confirmed by supabase.com

Did this fix it?

Cause 4 of 4

updateUser runs on a client that holds no logged-in user

1Check

The updateUser reference says it updates data for a logged in user. The Next.js guide says to use a browser client in Client Components and a server client, built from the request cookies, in server code.

grep -rn "createClient\|createServerClient\|createBrowserClient" app lib utils

2Fix

Call updateUser from a client built for that place: the server client in a Server Action, the browser client in a Client Component.

// Server Action, with the server client
const supabase = await createClient()
const { error } = await supabase.auth.updateUser({ password })

3Verify

Submit the new password and check that error is null.

# error is null and the user can sign in with the new password

Confirmed by supabase.com

Did this fix it?

How do I stop it coming back?

  • Write down in your repo that the Reset Password template must use the token_hash link, so nobody resets it to the default.
  • Add the update-password page to your protected routes, so it redirects when there is no user.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.