[GH-ISSUE #6158] Magic link login verifies email but returned session has emailVerified as false #10429

Closed
opened 2026-04-13 06:33:17 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @linardsblk on GitHub (Nov 21, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6158

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a user account using email/password. Do not verify e-mail.
  2. Login to the same user using magic link plugin.

Current vs. Expected behavior

Current behavior:

  • On magic link login, email is verified and updated in database.
  • The returned session user object still has emailVerified = false

Expected behavior:

  • On magic link login, email is verified and updated in database.
  • The returned session user object has emailVerified =true

What version of Better Auth are you using?

v1.3.7

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024",
    "release": "5.15.0-122-generic",
    "cpuCount": 64,
    "cpuModel": "AMD EPYC 7502 32-Core Processor",
    "totalMemory": "125.65 GB",
    "freeMemory": "64.78 GB"
  },
  "node": {
    "version": "v20.19.4",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.8.2"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Backend

Auth config (if applicable)


Additional context

While I am using an older version, I see that the source code still has this issue on latest version. I am willing to contribute a fix for this.

Originally created by @linardsblk on GitHub (Nov 21, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6158 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a user account using email/password. Do not verify e-mail. 2. Login to the same user using magic link plugin. ### Current vs. Expected behavior Current behavior: - On magic link login, email is verified and updated in database. - The returned session user object still has emailVerified = false Expected behavior: - On magic link login, email is verified and updated in database. - The returned session user object has emailVerified =true ### What version of Better Auth are you using? v1.3.7 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024", "release": "5.15.0-122-generic", "cpuCount": 64, "cpuModel": "AMD EPYC 7502 32-Core Processor", "totalMemory": "125.65 GB", "freeMemory": "64.78 GB" }, "node": { "version": "v20.19.4", "env": "development" }, "packageManager": { "name": "npm", "version": "10.8.2" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context While I am using an older version, I see that the source code still has this issue on latest version. I am willing to contribute a fix for this.
GiteaMirror added the lockedbug labels 2026-04-13 06:33:17 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 21, 2025):

Hi there, thanks for raising this! It looks like the magic link flow is correctly updating the email verification status in the database, but the session object isn’t reflecting that change immediately. One possible explanation is that the session object is being generated from an earlier cache state or before the new verification state has been fully propagated. I recommend verifying that the emailVerified flag is updated in the database before minting the session token and checking if a subsequent session fetch (for instance, after a page refresh or a forced session update) returns the correct state. Since you mentioned you’re on v1.3.7 and see the same behavior in the latest code, it might be a good candidate for a fix.

Would you be able to try a temporary workaround such as invalidating the session cache or manually re-fetching the user data in your magic link flow? Tag @better-auth-agent if you would like an answer from the Agent. What steps have you already attempted to ensure the session refresh reflects the updated verified status?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3562190773 --> @better-auth-agent[bot] commented on GitHub (Nov 21, 2025): Hi there, thanks for raising this! It looks like the magic link flow is correctly updating the email verification status in the database, but the session object isn’t reflecting that change immediately. One possible explanation is that the session object is being generated from an earlier cache state or before the new verification state has been fully propagated. I recommend verifying that the emailVerified flag is updated in the database before minting the session token and checking if a subsequent session fetch (for instance, after a page refresh or a forced session update) returns the correct state. Since you mentioned you’re on v1.3.7 and see the same behavior in the latest code, it might be a good candidate for a fix. Would you be able to try a temporary workaround such as invalidating the session cache or manually re-fetching the user data in your magic link flow? Tag @better-auth-agent if you would like an answer from the Agent. What steps have you already attempted to ensure the session refresh reflects the updated verified status? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 21, 2025):

Hi @linardsblk! I'm Dosu and I’m helping the better-auth team.

This is a confirmed bug in Better Auth: after magic link login, the user's emailVerified field is updated in the database, but the session user object may still show emailVerified as false. This happens because the session is created using a stale user object that hasn't been refreshed after the update. As a result, the session and any cached session data (like in Redis or cookies) can return outdated values until the session is refreshed or expires details.

To fix this, the magic link verification handler should re-fetch the user from the database after updating emailVerified, and use this fresh user object when creating the session and returning the response. If you want to contribute a fix, update the magic link plugin so that after calling updateUser, it assigns the returned user object to the user variable and uses that for session creation and the response payload.

As a workaround, you can manually refresh or invalidate the session after email verification, or refetch the session on the client after login to ensure you get the updated emailVerified status workaround example.

Let me know if you want a code pointer for where to make this change!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3562227022 --> @dosubot[bot] commented on GitHub (Nov 21, 2025): <!-- Greeting --> Hi @linardsblk! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a confirmed bug in Better Auth: after magic link login, the user's emailVerified field is updated in the database, but the session user object may still show emailVerified as false. This happens because the session is created using a stale user object that hasn't been refreshed after the update. As a result, the session and any cached session data (like in Redis or cookies) can return outdated values until the session is refreshed or expires [details](https://github.com/better-auth/better-auth/issues/4721). To fix this, the magic link verification handler should re-fetch the user from the database after updating emailVerified, and use this fresh user object when creating the session and returning the response. If you want to contribute a fix, update the magic link plugin so that after calling updateUser, it assigns the returned user object to the user variable and uses that for session creation and the response payload. As a workaround, you can manually refresh or invalidate the session after email verification, or refetch the session on the client after login to ensure you get the updated emailVerified status [workaround example](https://github.com/better-auth/better-auth/issues/4721). Let me know if you want a code pointer for where to make this change! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d4bddb32-fd17-4a1f-a0bd-68e77d0ab924?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6158)
Author
Owner

@redmundas commented on GitHub (Dec 17, 2025):

I'm still having this issue with version 1.4.7

<!-- gh-comment-id:3667360549 --> @redmundas commented on GitHub (Dec 17, 2025): I'm still having this issue with version `1.4.7`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10429