[PR #4850] [CLOSED] feat: add email subaddressing normalization #22515

Closed
opened 2026-04-15 21:06:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4850
Author: @Pankaj3112
Created: 9/23/2025
Status: Closed

Base: canaryHead: feat/email-subaddressing-normalization


📝 Commits (10+)

  • 1c3104c feat: add normalizeEmail function and option for normalizing email subaddress
  • 34b001b test: add tests for email subaddressing normalization
  • ec489e1 Merge branch 'canary' into feat/email-subaddressing-normalization
  • f2b7780 fix: pass context options to normalizeEmail in createInvitation
  • f377c68 Merge remote-tracking branch 'origin/canary' into feat/email-subaddressing-normalization
  • 6b8e952 chore: fix linting issues and format code
  • 3dc363f fix: normalize email to lowercase in createEmailVerificationToken
  • 1a8810c fix: update email in tests to use oauthuser format for subaddressing
  • 0f042d4 fix: cubic suggestions
  • a364b32 style: lint:fix

📊 Changes

14 files changed (+279 additions, -29 deletions)

View changed files

📝 packages/better-auth/src/api/routes/reset-password.test.ts (+52 -0)
📝 packages/better-auth/src/api/routes/sign-in.test.ts (+22 -0)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+26 -0)
📝 packages/better-auth/src/api/routes/sign-up.ts (+1 -1)
📝 packages/better-auth/src/api/routes/update-user.test.ts (+21 -0)
📝 packages/better-auth/src/api/routes/update-user.ts (+2 -1)
📝 packages/better-auth/src/db/internal-adapter.test.ts (+73 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+10 -5)
📝 packages/better-auth/src/oauth2/link-account.ts (+9 -10)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+5 -3)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+6 -3)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+19 -6)
📝 packages/better-auth/src/types/options.ts (+6 -0)
packages/better-auth/src/utils/email.ts (+27 -0)

📄 Description

What this PR does

This PR adds support for normalizing email addresses by removing the subaddressing portion (the + part in email addresses). When enabled, this prevents users from creating multiple accounts with variants of the same base email address.

Configuration

This feature is opt-in via a new configuration option:

const auth = initBetterAuth({
  user: {
    normalizeEmailSubaddressing: true // Disabled by default
  }
})

Benefits

  • Prevents duplicate accounts (user@example.com and user+tag@example.com are treated as the same user)
  • More consistent user experience across authentication flows
  • Helps prevent potential abuse during registration
  • Aligns with how major email providers handle addresses

Testing

Added tests for:

  • Sign-in with subaddressed emails
  • Sign-up with subaddressed emails
  • Password reset flows
  • Email change verification

Breaking changes

None - this feature is completely opt-in and doesn't affect existing behavior unless explicitly enabled.

Closes #4671


Summary by cubic

Adds opt-in email subaddressing normalization so user+tag@example.com is treated the same as user@example.com across auth and org flows. Prevents duplicate accounts and aligns behavior with major providers, fulfilling Linear #4671.

  • New Features

    • Added user.normalizeEmailSubaddressing option (default: false) and a normalizeEmail utility that lowercases and strips “+” aliases when enabled.
    • Applied normalization in user create/find/update, OAuth linking/generic OAuth, changeEmail, password reset, and organization invitations.
  • Migration

    • To enable, set user.normalizeEmailSubaddressing: true in BetterAuth options.
    • No breaking changes; behavior is unchanged unless enabled.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4850 **Author:** [@Pankaj3112](https://github.com/Pankaj3112) **Created:** 9/23/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/email-subaddressing-normalization` --- ### 📝 Commits (10+) - [`1c3104c`](https://github.com/better-auth/better-auth/commit/1c3104c7d1c6397a2cdddf2e4ef0e20a7c51331e) feat: add normalizeEmail function and option for normalizing email subaddress - [`34b001b`](https://github.com/better-auth/better-auth/commit/34b001bfe6feddb3571786c6f975ab387a5013d5) test: add tests for email subaddressing normalization - [`ec489e1`](https://github.com/better-auth/better-auth/commit/ec489e1f9c65c05fe296b0bcca34a401ae0fafe3) Merge branch 'canary' into feat/email-subaddressing-normalization - [`f2b7780`](https://github.com/better-auth/better-auth/commit/f2b7780739542203f90825f950fe4a528a32cfae) fix: pass context options to normalizeEmail in createInvitation - [`f377c68`](https://github.com/better-auth/better-auth/commit/f377c68e2e4f783a91e025a792c72d1a4bc96a7e) Merge remote-tracking branch 'origin/canary' into feat/email-subaddressing-normalization - [`6b8e952`](https://github.com/better-auth/better-auth/commit/6b8e952649f58caf208cecd5db58044726ab4c9d) chore: fix linting issues and format code - [`3dc363f`](https://github.com/better-auth/better-auth/commit/3dc363ff162c9467ba3874520485b55212006fdf) fix: normalize email to lowercase in createEmailVerificationToken - [`1a8810c`](https://github.com/better-auth/better-auth/commit/1a8810c1dd94146ae9ef5b4a8c66d305d6a4ba8f) fix: update email in tests to use oauthuser format for subaddressing - [`0f042d4`](https://github.com/better-auth/better-auth/commit/0f042d4fd9b785382c91087f44b380e2b1334763) fix: cubic suggestions - [`a364b32`](https://github.com/better-auth/better-auth/commit/a364b3285107978e98227d1375dde5441ac9bb83) style: lint:fix ### 📊 Changes **14 files changed** (+279 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/reset-password.test.ts` (+52 -0) 📝 `packages/better-auth/src/api/routes/sign-in.test.ts` (+22 -0) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+26 -0) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+21 -0) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+2 -1) 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+73 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+10 -5) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+9 -10) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+5 -3) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+6 -3) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+19 -6) 📝 `packages/better-auth/src/types/options.ts` (+6 -0) ➕ `packages/better-auth/src/utils/email.ts` (+27 -0) </details> ### 📄 Description ## What this PR does This PR adds support for normalizing email addresses by removing the subaddressing portion (the `+` part in email addresses). When enabled, this prevents users from creating multiple accounts with variants of the same base email address. ## Configuration This feature is opt-in via a new configuration option: ```typescript const auth = initBetterAuth({ user: { normalizeEmailSubaddressing: true // Disabled by default } }) ``` ## Benefits - Prevents duplicate accounts (user@example.com and user+tag@example.com are treated as the same user) - More consistent user experience across authentication flows - Helps prevent potential abuse during registration - Aligns with how major email providers handle addresses ## Testing Added tests for: - Sign-in with subaddressed emails - Sign-up with subaddressed emails - Password reset flows - Email change verification ## Breaking changes None - this feature is completely opt-in and doesn't affect existing behavior unless explicitly enabled. Closes #4671 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds opt-in email subaddressing normalization so user+tag@example.com is treated the same as user@example.com across auth and org flows. Prevents duplicate accounts and aligns behavior with major providers, fulfilling Linear #4671. - **New Features** - Added user.normalizeEmailSubaddressing option (default: false) and a normalizeEmail utility that lowercases and strips “+” aliases when enabled. - Applied normalization in user create/find/update, OAuth linking/generic OAuth, changeEmail, password reset, and organization invitations. - **Migration** - To enable, set user.normalizeEmailSubaddressing: true in BetterAuth options. - No breaking changes; behavior is unchanged unless enabled. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 21:06:04 -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#22515