Issue with email change #713

Closed
opened 2026-03-13 08:01:24 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @hussein-raji-mappa on GitHub (Feb 20, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create an account
  2. Request an email change but an email with upper and lower case characters
  3. Open your email and click the token url.
  4. After redirecting back to your application, signout
  5. sign back in using the exact email you used for the change (with the upper and lower case character).

Current vs. Expected behavior

Current behaviour: a new user get's created. also you're unable to verify the new email
Expected behaviour: you sign back in with the new email and you're the same user

What version of Better Auth are you using?

1.1.18

Provide environment information

- OS: Windows 10
- Browser: chrome

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

Package

Auth config (if applicable)


Additional context

The new email doesn't get converted to lower case before it gets stored in the db. I saw this in the changeEmail handler. See below:

  if (ctx.context.session.user.emailVerified !== true) {
    await ctx.context.internalAdapter.updateUserByEmail(
      ctx.context.session.user.email,
      {
        email: ctx.body.newEmail
      }
    );
    return ctx.json({
      status: true
    });
  }

updateUserByEmail: async (email, data) => {
  const user = await updateWithHooks(
    data,
    [
      {
        field: "email",
        value: email
      }
    ],
    "user"
  );
  return user;
},

When using the findUserByEmail callback the email is normalized hence my issue:

  findUserByEmail: async (email, options2) => {
    const user = await adapter.findOne({
      model: "user",
      where: [
        {
          value: email.toLowerCase(),
          field: "email"
        }
      ]
    });
Originally created by @hussein-raji-mappa on GitHub (Feb 20, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create an account 2. Request an email change but an email with upper and lower case characters 3. Open your email and click the token url. 4. After redirecting back to your application, signout 5. sign back in using the exact email you used for the change (with the upper and lower case character). ### Current vs. Expected behavior Current behaviour: a new user get's created. also you're unable to verify the new email Expected behaviour: you sign back in with the new email and you're the same user ### What version of Better Auth are you using? 1.1.18 ### Provide environment information ```bash - OS: Windows 10 - Browser: chrome ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript ``` ### Additional context The new email doesn't get converted to lower case before it gets stored in the db. I saw this in the changeEmail handler. See below: ``` if (ctx.context.session.user.emailVerified !== true) { await ctx.context.internalAdapter.updateUserByEmail( ctx.context.session.user.email, { email: ctx.body.newEmail } ); return ctx.json({ status: true }); } updateUserByEmail: async (email, data) => { const user = await updateWithHooks( data, [ { field: "email", value: email } ], "user" ); return user; }, ``` When using the findUserByEmail callback the email is normalized hence my issue: ``` findUserByEmail: async (email, options2) => { const user = await adapter.findOne({ model: "user", where: [ { value: email.toLowerCase(), field: "email" } ] }); ```
GiteaMirror added the bug label 2026-03-13 08:01:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#713