[PR #5593] [MERGED] Add missing email validation #31705

Closed
opened 2026-04-17 22:35:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5593
Author: @ahmedriad1
Created: 10/26/2025
Status: Merged
Merged: 10/27/2025
Merged by: @himself65

Base: canaryHead: fix/missing-email-validation


📝 Commits (5)

  • 04ceba8 fix: validate email when creating invites
  • 32692d1 fix: validate emails when creating users as admin
  • 78668db refactor: remove email regex in favor of zod & remove redundant error codes that exist in BASE_ERROR_CODES
  • 6881148 chore: fix linting
  • abc5cf8 Merge branch 'canary' into fix/missing-email-validation

📊 Changes

3 files changed (+46 additions, -26 deletions)

View changed files

📝 packages/better-auth/src/plugins/admin/admin.ts (+12 -4)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+21 -19)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+13 -3)

📄 Description

https://github.com/user-attachments/assets/318de27c-c5aa-4064-834b-685b318868f0

I found out creating invites using the organization plugin doesn't validate emails https://github.com/agentset-ai/agentset/pull/34

I looked more into the codebase and found it's missing in other places too. So I made this PR that does the following:

  1. Validate email when creating invites (organization plugin)
  2. Validate email when creating users as admin (admin plugin)
  3. Refactor email validation to use zod instead of manual regex & remove redundant error codes that already exist in BASE_ERROR_CODES (email-otp plugin)

Summary by cubic

Add email validation to organization invites and admin user creation, and standardize email handling and errors in email-otp. Prevents invalid invites/sign-ups and ensures consistent error messages.

  • Bug Fixes

    • Validate emails when creating organization invites.
    • Validate emails when admins create users.
    • Lowercase emails before lookup and creation to prevent duplicates.
  • Refactors

    • Replace manual regex with zod email validation in email-otp.
    • Use BASE_ERROR_CODES for INVALID_EMAIL and USER_NOT_FOUND; remove redundant local codes.

🔄 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/5593 **Author:** [@ahmedriad1](https://github.com/ahmedriad1) **Created:** 10/26/2025 **Status:** ✅ Merged **Merged:** 10/27/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/missing-email-validation` --- ### 📝 Commits (5) - [`04ceba8`](https://github.com/better-auth/better-auth/commit/04ceba863387a1e3653a9dd72d76516327e33bbf) fix: validate email when creating invites - [`32692d1`](https://github.com/better-auth/better-auth/commit/32692d1e12d9153f11fd71f75e7dafbc70b0dd1f) fix: validate emails when creating users as admin - [`78668db`](https://github.com/better-auth/better-auth/commit/78668db64c4fa94ba43b1a80f2d101dac88916e8) refactor: remove email regex in favor of zod & remove redundant error codes that exist in BASE_ERROR_CODES - [`6881148`](https://github.com/better-auth/better-auth/commit/6881148cccfb44cf27e4eebde928f0c419719564) chore: fix linting - [`abc5cf8`](https://github.com/better-auth/better-auth/commit/abc5cf8ba3c8ec57bbc0f67e062d17f592dd7f85) Merge branch 'canary' into fix/missing-email-validation ### 📊 Changes **3 files changed** (+46 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+12 -4) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+21 -19) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+13 -3) </details> ### 📄 Description https://github.com/user-attachments/assets/318de27c-c5aa-4064-834b-685b318868f0 I found out creating invites using the `organization` plugin doesn't validate emails https://github.com/agentset-ai/agentset/pull/34 I looked more into the codebase and found it's missing in other places too. So I made this PR that does the following: 1. Validate email when creating invites (`organization` plugin) 2. Validate email when creating users as admin (`admin` plugin) 3. Refactor email validation to use zod instead of manual regex & remove redundant error codes that already exist in `BASE_ERROR_CODES` (`email-otp` plugin) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add email validation to organization invites and admin user creation, and standardize email handling and errors in email-otp. Prevents invalid invites/sign-ups and ensures consistent error messages. - **Bug Fixes** - Validate emails when creating organization invites. - Validate emails when admins create users. - Lowercase emails before lookup and creation to prevent duplicates. - **Refactors** - Replace manual regex with zod email validation in email-otp. - Use BASE_ERROR_CODES for INVALID_EMAIL and USER_NOT_FOUND; remove redundant local codes. <!-- 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-17 22:35:34 -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#31705