[PR #5571] Validator #31693

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5571
Author: @R5dan
Created: 10/25/2025
Status: 🔄 Open

Base: mainHead: validator


📝 Commits (2)

📊 Changes

13 files changed (+158 additions, -111 deletions)

View changed files

📝 packages/better-auth/src/api/routes/reset-password.ts (+15 -9)
📝 packages/better-auth/src/api/routes/sign-up.ts (+8 -16)
📝 packages/better-auth/src/api/routes/update-user.ts (+25 -24)
📝 packages/better-auth/src/db/schema.ts (+1 -1)
📝 packages/better-auth/src/init.ts (+2 -4)
📝 packages/better-auth/src/plugins/api-key/index.ts (+1 -0)
📝 packages/better-auth/src/plugins/username/error-codes.ts (+1 -2)
📝 packages/better-auth/src/plugins/username/index.ts (+25 -37)
📝 packages/core/src/db/type.ts (+3 -3)
📝 packages/core/src/types/context.ts (+2 -4)
📝 packages/core/src/types/init-options.ts (+4 -9)
packages/core/src/types/standard-schema.ts (+70 -0)
📝 packages/telemetry/src/detectors/detect-auth-config.ts (+1 -2)

📄 Description

Requires #5570

Replaces manual validation by fields like minPasswordLength with a passwordSchema field that takes a standard schema type for validation. Does not replace the validatePasswordFunction (and equivalent) fields.


Summary by cubic

Switch password and username validation to a standard schema-based approach, replacing min/max length checks with a configurable validator. Adds a StandardSchemaV1 interface and updates routes, context, and plugins to use it while keeping custom password validation functions.

  • Refactors

    • Added StandardSchemaV1 and replaced min/max password config with password.validator in context (default: z.string().min(8).max(128)).
    • Updated sign-up, reset-password, and change/set password endpoints to use schema validation with async support.
    • Migrated username plugin to usernameSchema, removed min/max options, and updated error codes to USERNAME_SCHEMA_VALIDATION_FAILED.
    • Switched DB field validators and parseInputData to use the standard schema validate API.
    • Adjusted telemetry to report schema-based configuration.
  • Migration

    • Replace emailAndPassword.minPasswordLength/maxPasswordLength with emailAndPassword.validator (StandardSchemaV1).
    • Update any usage of ctx.context.password.config to ctx.context.password.validator.
    • For the username plugin, replace minUsernameLength/maxUsernameLength with usernameSchema and handle the new error code.

🔄 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/5571 **Author:** [@R5dan](https://github.com/R5dan) **Created:** 10/25/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `validator` --- ### 📝 Commits (2) - [`8df3065`](https://github.com/better-auth/better-auth/commit/8df3065a45e087b4cf637ccae8663b810b51d602) standard schema - [`a9fb938`](https://github.com/better-auth/better-auth/commit/a9fb93862e8b5a5657c380b4215fcb2714c4f02d) validation ### 📊 Changes **13 files changed** (+158 additions, -111 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/reset-password.ts` (+15 -9) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+8 -16) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+25 -24) 📝 `packages/better-auth/src/db/schema.ts` (+1 -1) 📝 `packages/better-auth/src/init.ts` (+2 -4) 📝 `packages/better-auth/src/plugins/api-key/index.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/username/error-codes.ts` (+1 -2) 📝 `packages/better-auth/src/plugins/username/index.ts` (+25 -37) 📝 `packages/core/src/db/type.ts` (+3 -3) 📝 `packages/core/src/types/context.ts` (+2 -4) 📝 `packages/core/src/types/init-options.ts` (+4 -9) ➕ `packages/core/src/types/standard-schema.ts` (+70 -0) 📝 `packages/telemetry/src/detectors/detect-auth-config.ts` (+1 -2) </details> ### 📄 Description Requires #5570 Replaces manual validation by fields like `minPasswordLength` with a `passwordSchema` field that takes a standard schema type for validation. Does not replace the `validatePasswordFunction` (and equivalent) fields. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Switch password and username validation to a standard schema-based approach, replacing min/max length checks with a configurable validator. Adds a StandardSchemaV1 interface and updates routes, context, and plugins to use it while keeping custom password validation functions. - **Refactors** - Added StandardSchemaV1 and replaced min/max password config with password.validator in context (default: z.string().min(8).max(128)). - Updated sign-up, reset-password, and change/set password endpoints to use schema validation with async support. - Migrated username plugin to usernameSchema, removed min/max options, and updated error codes to USERNAME_SCHEMA_VALIDATION_FAILED. - Switched DB field validators and parseInputData to use the standard schema validate API. - Adjusted telemetry to report schema-based configuration. - **Migration** - Replace emailAndPassword.minPasswordLength/maxPasswordLength with emailAndPassword.validator (StandardSchemaV1). - Update any usage of ctx.context.password.config to ctx.context.password.validator. - For the username plugin, replace minUsernameLength/maxUsernameLength with usernameSchema and handle the new error code. <!-- 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:34:56 -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#31693