[GH-ISSUE #1286] emailOtp.verifyEmail does not revalidate the user session #26000

Closed
opened 2026-04-17 16:23:01 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @itsyoboieltr on GitHub (Jan 27, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1286

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I was told in https://discord.com/channels/1288403910284935179/1333163775880335502/1333163775880335502 to create an issue for this.

When a user is logged in, and verifies their email using emailOtp.verifyEmail, the emailVerified field is not updated on the client if there is a cookie cache. Once the cookie cache expires, and the page is manually refreshed, only then will the emailVerified field return true. This cookie cache should automatically be revalidated (similar to how it is done when signing in, or signing out), so that the useSession hook always returns the correct value.

Current vs. Expected behavior

Current behaviour:

  1. user logs in (emailVerified: false)
  2. useSession returns emailVerified: false
  3. user asks for OTP using emailOtp.sendVerificationOtp
  4. user enters OTP using emailOtp.verifyEmail to verify their email.
  5. After emailOtp.verifyEmail succeeds, useSession still returns emailVerified: false (the issue is that this value does not get updated to true)

Expected behaviour:

  1. user logs in (emailVerified: false)
  2. useSession returns emailVerified: false
  3. user asks for OTP using emailOtp.sendVerificationOtp
  4. user enters OTP using emailOtp.verifyEmail to verify their email.
  5. After emailOtp.verifyEmail succeeds, useSession returns emailVerified: true (cookie cache gets revalidated)

What version of Better Auth are you using?

1.1.14

Provide environment information

- OS: macOS
- Browser: Chrome

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

No response

Additional context

No response

Originally created by @itsyoboieltr on GitHub (Jan 27, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1286 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I was told in https://discord.com/channels/1288403910284935179/1333163775880335502/1333163775880335502 to create an issue for this. When a user is logged in, and verifies their email using `emailOtp.verifyEmail`, the `emailVerified` field is not updated on the client if there is a cookie cache. Once the cookie cache expires, and the page is manually refreshed, only then will the `emailVerified` field return true. This cookie cache should automatically be revalidated (similar to how it is done when signing in, or signing out), so that the `useSession` hook always returns the correct value. ### Current vs. Expected behavior Current behaviour: 1. user logs in (`emailVerified: false`) 2. `useSession` returns `emailVerified: false` 3. user asks for OTP using `emailOtp.sendVerificationOtp` 4. user enters OTP using `emailOtp.verifyEmail` to verify their email. 5. After `emailOtp.verifyEmail` succeeds, `useSession` still returns `emailVerified: false` (the issue is that this value does not get updated to true) Expected behaviour: 1. user logs in (`emailVerified: false`) 2. `useSession` returns `emailVerified: false` 3. user asks for OTP using `emailOtp.sendVerificationOtp` 4. user enters OTP using `emailOtp.verifyEmail` to verify their email. 5. After `emailOtp.verifyEmail` succeeds, `useSession` returns `emailVerified: true` (cookie cache gets revalidated) ### What version of Better Auth are you using? 1.1.14 ### Provide environment information ```bash - OS: macOS - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) _No response_ ### Additional context _No response_
GiteaMirror added the help wantedlockedbug labels 2026-04-17 16:23:01 -05:00
Author
Owner

@dassaswat commented on GitHub (Jan 27, 2025):

Is the value getting updated in the Database ?

<!-- gh-comment-id:2616865201 --> @dassaswat commented on GitHub (Jan 27, 2025): Is the value getting updated in the Database ?
Author
Owner

@itsyoboieltr commented on GitHub (Jan 27, 2025):

@dassaswat in the database it is updated, yes.

<!-- gh-comment-id:2616896945 --> @itsyoboieltr commented on GitHub (Jan 27, 2025): @dassaswat in the database it is updated, yes.
Author
Owner

@IronHeartDan commented on GitHub (Feb 5, 2025):

+1

<!-- gh-comment-id:2636236640 --> @IronHeartDan commented on GitHub (Feb 5, 2025): +1
Author
Owner

@samir1498 commented on GitHub (Apr 30, 2025):

is there a proper fix for this issue?

<!-- gh-comment-id:2841363405 --> @samir1498 commented on GitHub (Apr 30, 2025): is there a proper fix for this issue?
Author
Owner

@peyronoscar commented on GitHub (Apr 30, 2025):

I had the same issue with the session cookie cache when using email verification on email sign in. This solved it for me:

const auth = betterAuth({
    emailVerification: {
        autoSignInAfterVerification: true
    }
})

Docs

<!-- gh-comment-id:2843246671 --> @peyronoscar commented on GitHub (Apr 30, 2025): I had the same issue with the session cookie cache when using email verification on email sign in. This solved it for me: ``` const auth = betterAuth({ emailVerification: { autoSignInAfterVerification: true } }) ``` [Docs](https://www.better-auth.com/docs/concepts/email#auto-signin-after-verification)
Author
Owner

@dosubot[bot] commented on GitHub (Jul 30, 2025):

Hi, @itsyoboieltr. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that after verifying your email with emailOtp.verifyEmail, the session's emailVerified field does not update immediately due to cookie caching.
  • The database updates correctly, but useSession still shows false until a manual refresh.
  • Commenters confirmed this is a known issue with session revalidation not happening automatically.
  • A workaround was shared by enabling autoSignInAfterVerification in the emailVerification config, which forces the session to refresh after verification.
  • The issue remains open as users are seeking a proper fix beyond the workaround.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3136947748 --> @dosubot[bot] commented on GitHub (Jul 30, 2025): Hi, @itsyoboieltr. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that after verifying your email with emailOtp.verifyEmail, the session's emailVerified field does not update immediately due to cookie caching. - The database updates correctly, but useSession still shows false until a manual refresh. - Commenters confirmed this is a known issue with session revalidation not happening automatically. - A workaround was shared by enabling autoSignInAfterVerification in the emailVerification config, which forces the session to refresh after verification. - The issue remains open as users are seeking a proper fix beyond the workaround. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@itsyoboieltr commented on GitHub (Aug 3, 2025):

I tested it on the latest version, and the issue is still relevant with the latest version of better-auth.

<!-- gh-comment-id:3148632195 --> @itsyoboieltr commented on GitHub (Aug 3, 2025): I tested it on the latest version, and the issue is still relevant with the latest version of better-auth.
Author
Owner

@sonnm commented on GitHub (Oct 2, 2025):

const { refetch } = authClient.useSession()
await authClient.emailOtp.verifyEmail({ email, otp }, { onSuccess: () => refetch() })

This approach worked for me.

<!-- gh-comment-id:3362510172 --> @sonnm commented on GitHub (Oct 2, 2025): ``` const { refetch } = authClient.useSession() await authClient.emailOtp.verifyEmail({ email, otp }, { onSuccess: () => refetch() }) ``` This approach worked for me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26000