[PR #5885] [CLOSED] type ( refactor ) #6296

Closed
opened 2026-03-13 12:53:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5885
Author: @darad25
Created: 11/10/2025
Status: Closed

Base: canaryHead: type/refactor


📝 Commits (10+)

📊 Changes

17 files changed (+435 additions, -107 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.ts (+1 -1)
📝 packages/better-auth/src/api/routes/email-verification.ts (+70 -31)
📝 packages/better-auth/src/api/routes/reset-password.ts (+31 -7)
📝 packages/better-auth/src/api/routes/session.ts (+5 -0)
📝 packages/better-auth/src/api/routes/sign-in.ts (+35 -3)
📝 packages/better-auth/src/api/routes/sign-up.ts (+20 -4)
📝 packages/better-auth/src/api/routes/update-user.ts (+50 -9)
📝 packages/better-auth/src/cookies/cookie-utils.ts (+41 -4)
📝 packages/better-auth/src/cookies/index.ts (+30 -2)
📝 packages/better-auth/src/cookies/session-store.ts (+32 -11)
📝 packages/better-auth/src/db/get-migration.ts (+21 -2)
📝 packages/better-auth/src/db/internal-adapter.ts (+5 -3)
📝 packages/better-auth/src/db/with-hooks.ts (+6 -4)
📝 packages/better-auth/src/oauth2/link-account.ts (+40 -11)
📝 packages/better-auth/src/oauth2/state.ts (+13 -5)
📝 packages/better-auth/src/plugins/admin/admin.ts (+13 -7)
📝 packages/better-auth/src/plugins/admin/routes.ts (+22 -3)

📄 Description

i created an ensure email verification helper, it ensure email verification is enabled in options and return the object, it helps make the send verification email fn function simpler and more efficient, i feel using helpers gives code a better structure.


Summary by cubic

Centralized email verification checks and URL building, added secure OAuth refresh token handling, and cleared stale session data on expiry. Improved callback URL handling across reset-password, sign-in, sign-up, change-email, and delete-user, plus hardened OAuth state parsing and fixed update hooks.

  • Refactors

    • Email verification: applied ensureEmailVerificationEnabled across routes, switched to zod/v4, and centralized buildVerificationUrl.
    • OAuth/linking/cookies/migrations: decrypt refreshToken before refresh; clear session-data cookie on missing/expired session; include callback URLs in OAuth state and optionally store account cookie after linking; normalize cross-subdomain cookie domain; chunk session/account cookies by byte length; arrays stored as JSON and avoid NOT NULL without defaults; with-hooks: pass actualData to update.before and reuse adapter instance.
    • Sign-up/update-user: explicit schema and originCheck-decode callbackURL; lowercase email for lookup/create/token; block restricted fields and validate name/image.
  • Bug Fixes

    • Delete-user: fix session freshness check to prevent false “expired” errors.
    • Cookies: split combined Set-Cookie when Expires contains commas.
    • Internal adapter: correct session TTL math and avoid premature loop exits.
    • OAuth state: fix cookie maxAge units and handle bad JSON with safe redirect.

Written for commit 0841e67540. 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/5885 **Author:** [@darad25](https://github.com/darad25) **Created:** 11/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `type/refactor` --- ### 📝 Commits (10+) - [`26c0b8e`](https://github.com/better-auth/better-auth/commit/26c0b8eff850e64901a3afb23ffd86ee3f37737b) first commit - [`146c8d4`](https://github.com/better-auth/better-auth/commit/146c8d4cf9862bcf842219e7ebf9c2f3f411cb40) first commit - [`c4344a9`](https://github.com/better-auth/better-auth/commit/c4344a9394d9a0773b2c3ca18a5916b0a62a03bb) first commit - [`2165675`](https://github.com/better-auth/better-auth/commit/2165675be19f00db7fb0a0ed00eaa32fd9c16c14) first commit - [`eb7c5de`](https://github.com/better-auth/better-auth/commit/eb7c5dec273b0b06980b053de8504fab581b1506) Merge branch 'canary' into type/refactor - [`6405e1d`](https://github.com/better-auth/better-auth/commit/6405e1d0d97bd5b7becf755206b726dcc7792d45) i created a buildVerificationUrl helper to make the code easy to understand and make changes. - [`1233a9f`](https://github.com/better-auth/better-auth/commit/1233a9f8795f7441c1a74d0e8bb01e9bbfa54a10) Merge branch 'type/refactor' of https://github.com/darad25/better-auth into type/refactor - [`aea10d0`](https://github.com/better-auth/better-auth/commit/aea10d04b758ce85363c95ac82912b448f7883ed) first commit - [`8694d00`](https://github.com/better-auth/better-auth/commit/8694d00945b33f91712fe75a131b915add4d0868) Merge branch 'canary' into type/refactor - [`0146f89`](https://github.com/better-auth/better-auth/commit/0146f897068e2e6db9337658095d353bb953f0fc) Merge branch 'better-auth:canary' into type/refactor ### 📊 Changes **17 files changed** (+435 additions, -107 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+70 -31) 📝 `packages/better-auth/src/api/routes/reset-password.ts` (+31 -7) 📝 `packages/better-auth/src/api/routes/session.ts` (+5 -0) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+35 -3) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+20 -4) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+50 -9) 📝 `packages/better-auth/src/cookies/cookie-utils.ts` (+41 -4) 📝 `packages/better-auth/src/cookies/index.ts` (+30 -2) 📝 `packages/better-auth/src/cookies/session-store.ts` (+32 -11) 📝 `packages/better-auth/src/db/get-migration.ts` (+21 -2) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+5 -3) 📝 `packages/better-auth/src/db/with-hooks.ts` (+6 -4) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+40 -11) 📝 `packages/better-auth/src/oauth2/state.ts` (+13 -5) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+13 -7) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+22 -3) </details> ### 📄 Description i created an ensure email verification helper, it ensure email verification is enabled in options and return the object, it helps make the send verification email fn function simpler and more efficient, i feel using helpers gives code a better structure. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Centralized email verification checks and URL building, added secure OAuth refresh token handling, and cleared stale session data on expiry. Improved callback URL handling across reset-password, sign-in, sign-up, change-email, and delete-user, plus hardened OAuth state parsing and fixed update hooks. - **Refactors** - Email verification: applied ensureEmailVerificationEnabled across routes, switched to zod/v4, and centralized buildVerificationUrl. - OAuth/linking/cookies/migrations: decrypt refreshToken before refresh; clear session-data cookie on missing/expired session; include callback URLs in OAuth state and optionally store account cookie after linking; normalize cross-subdomain cookie domain; chunk session/account cookies by byte length; arrays stored as JSON and avoid NOT NULL without defaults; with-hooks: pass actualData to update.before and reuse adapter instance. - Sign-up/update-user: explicit schema and originCheck-decode callbackURL; lowercase email for lookup/create/token; block restricted fields and validate name/image. - **Bug Fixes** - Delete-user: fix session freshness check to prevent false “expired” errors. - Cookies: split combined Set-Cookie when Expires contains commas. - Internal adapter: correct session TTL math and avoid premature loop exits. - OAuth state: fix cookie maxAge units and handle bad JSON with safe redirect. <sup>Written for commit 0841e67540890fac404aaeaf91dc2608d2d4f0f0. 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:53:49 -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#6296