[PR #5422] Add method to validate password reset tokens before use #5997

Open
opened 2026-03-13 12:44:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5422
Author: @jer-tan
Created: 10/20/2025
Status: 🔄 Open

Base: canaryHead: canary


📝 Commits (10+)

  • ef24533 feat(email&password): add validatePasswordResetToken client function and endpoint
  • 315b919 docs: update documentation for validateResetPasswordToken
  • 3d78d38 Merge branch 'canary' into canary
  • 673c68d chore: remove unused authentication functions from API
  • ca84974 chore: reorder import statements to include validatePasswordResetToken
  • 7cf7907 chore: remove deprecated forgetPasswordCallback
  • 1a532e0 Merge branch 'canary' into canary
  • 42a743b Merge branch 'canary' into canary
  • f7ff030 Merge branch 'canary' into canary
  • fa99b1c Merge branch 'canary' into canary

📊 Changes

6 files changed (+373 additions, -0 deletions)

View changed files

📝 docs/content/docs/authentication/email-password.mdx (+97 -0)
📝 packages/better-auth/src/api/index.ts (+2 -0)
📝 packages/better-auth/src/api/routes/password.test.ts (+54 -0)
📝 packages/better-auth/src/api/routes/password.ts (+69 -0)
📝 packages/better-auth/src/client/config.ts (+1 -0)
📝 packages/better-auth/src/plugins/open-api/__snapshots__/open-api.test.ts.snap (+150 -0)

📄 Description

Hello! I noticed that when users land on a password reset page, they don't know if their token is valid or expired until they actually try to submit the form. This can be frustrating for user, imagine filling out new password only to find out the link expired.

What's new

This PR adds a new validateResetPasswordToken method that lets you check if a reset token is still valid without consuming it.

Client usage:

const validation = await client.validateResetPasswordToken({ token });

if (validation.data?.valid) {
  // Show the reset form
} else {
  // Show error: token expired or invalid
}

Changes made

  • Server: Added /validate-reset-password-token POST endpoint that checks token validity and expiration
  • Client: The endpoint is automatically available as client.validateResetPasswordToken()
  • Tests: Added 3 test cases covering valid, invalid, and expired tokens
  • Docs: Updated the email-password authentication docs with usage examples including a React component

The validation returns:

{
  valid: boolean,
  message: string  // "Token is valid" | "Invalid token" | "Token has expired"
}

Testing

All tests pass including the 3 new validation tests:

  • Valid token returns { valid: true }
  • Invalid token returns { valid: false }
  • Expired token returns { valid: false }

Summary by cubic

Add a password reset token validator so users can see if their link is valid or expired before filling the form. Docs and OpenAPI updated.

  • New Features
    • Server: POST /validate-reset-password-token checks validity and expiry without consuming the token.
    • Client: validateResetPasswordToken({ token }) returns { valid, message } to gate the reset form.
    • Tests & docs: 3 tests (valid/invalid/expired) and updated docs with usage examples (incl. a React snippet).
    • OpenAPI: Endpoint added to the generated schema.

Written for commit cd774b9e9e. Summary will update on new commits.


🔄 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/5422 **Author:** [@jer-tan](https://github.com/jer-tan) **Created:** 10/20/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (10+) - [`ef24533`](https://github.com/better-auth/better-auth/commit/ef24533a8bd7e2f8725b2ac68ff4a24d6fa947fe) feat(email&password): add validatePasswordResetToken client function and endpoint - [`315b919`](https://github.com/better-auth/better-auth/commit/315b91932c287a1020ca904f500b72584020591d) docs: update documentation for validateResetPasswordToken - [`3d78d38`](https://github.com/better-auth/better-auth/commit/3d78d38d22e7047b8a807cff0591f82893783cb4) Merge branch 'canary' into canary - [`673c68d`](https://github.com/better-auth/better-auth/commit/673c68dad07abaf296d824317a7297ef9c6f81b4) chore: remove unused authentication functions from API - [`ca84974`](https://github.com/better-auth/better-auth/commit/ca84974ada06e05112106e765a08441173f11984) chore: reorder import statements to include validatePasswordResetToken - [`7cf7907`](https://github.com/better-auth/better-auth/commit/7cf7907ba3cbb6f8f857d79fc7d4c33f56ae4d91) chore: remove deprecated forgetPasswordCallback - [`1a532e0`](https://github.com/better-auth/better-auth/commit/1a532e04f97c87bce467cf55a8274e3802cdd8a7) Merge branch 'canary' into canary - [`42a743b`](https://github.com/better-auth/better-auth/commit/42a743bee834e1cdf50cb780687be0d8c42442bf) Merge branch 'canary' into canary - [`f7ff030`](https://github.com/better-auth/better-auth/commit/f7ff030f281b391fee305b2623e250bffd20a97d) Merge branch 'canary' into canary - [`fa99b1c`](https://github.com/better-auth/better-auth/commit/fa99b1c026af93dd1cece2c696fbdc7e3b07dfe6) Merge branch 'canary' into canary ### 📊 Changes **6 files changed** (+373 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/authentication/email-password.mdx` (+97 -0) 📝 `packages/better-auth/src/api/index.ts` (+2 -0) 📝 `packages/better-auth/src/api/routes/password.test.ts` (+54 -0) 📝 `packages/better-auth/src/api/routes/password.ts` (+69 -0) 📝 `packages/better-auth/src/client/config.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/open-api/__snapshots__/open-api.test.ts.snap` (+150 -0) </details> ### 📄 Description Hello! I noticed that when users land on a password reset page, they don't know if their token is valid or expired until they actually try to submit the form. This can be frustrating for user, imagine filling out new password only to find out the link expired. ### What's new This PR adds a new `validateResetPasswordToken` method that lets you check if a reset token is still valid without consuming it. **Client usage:** ```ts const validation = await client.validateResetPasswordToken({ token }); if (validation.data?.valid) { // Show the reset form } else { // Show error: token expired or invalid } ``` ### Changes made - **Server**: Added `/validate-reset-password-token` POST endpoint that checks token validity and expiration - **Client**: The endpoint is automatically available as `client.validateResetPasswordToken()` - **Tests**: Added 3 test cases covering valid, invalid, and expired tokens - **Docs**: Updated the email-password authentication docs with usage examples including a React component The validation returns: ```ts { valid: boolean, message: string // "Token is valid" | "Invalid token" | "Token has expired" } ``` ### Testing All tests pass including the 3 new validation tests: - Valid token returns `{ valid: true }` - Invalid token returns `{ valid: false }` - Expired token returns `{ valid: false }` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a password reset token validator so users can see if their link is valid or expired before filling the form. Docs and OpenAPI updated. - **New Features** - Server: POST /validate-reset-password-token checks validity and expiry without consuming the token. - Client: `validateResetPasswordToken({ token })` returns `{ valid, message }` to gate the reset form. - Tests & docs: 3 tests (valid/invalid/expired) and updated docs with usage examples (incl. a React snippet). - OpenAPI: Endpoint added to the generated schema. <sup>Written for commit cd774b9e9e22a73c40169f1a27e52de45d9b35a7. Summary will update on new commits.</sup> <!-- 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-03-13 12:44:09 -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#5997