[PR #5742] feat: add request state #14439

Closed
opened 2026-04-13 09:28:33 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5742

State: closed
Merged: Yes


Summary by cubic

Adds request-scoped state with AsyncLocalStorage to safely share schema-bound data across async boundaries, and runs auth endpoints within it or reuses an existing one. Enables validated OAuth additionalData to be passed through the flow and exposed to hooks via request state (not persisted).

  • New Features
    • RequestState using WeakMap<StandardSchemaV1, any>.
    • runWithRequestState(), getCurrentRequestState() (throws), hasRequestState(), getRequestStateAsyncLocalStorage().
    • defineRequestState(schema) for typed get/set.
    • Auth endpoints ensure a per-call request state and reuse when available.
    • OAuth middleware exposes getOauthState; set is internal to the flow.
    • OAuth: advanced.oauthConfig.additionalData { enabled?, schema?: StandardSchemaV1 } to validate and store data in request state.
    • signInSocial, generic OAuth, and linkSocialAccount accept additionalData; forwarded and available in hooks (not stored in DB).

Written for commit ae7fccda44. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5742 **State:** closed **Merged:** Yes --- <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds request-scoped state with AsyncLocalStorage to safely share schema-bound data across async boundaries, and runs auth endpoints within it or reuses an existing one. Enables validated OAuth additionalData to be passed through the flow and exposed to hooks via request state (not persisted). - **New Features** - RequestState using WeakMap<StandardSchemaV1, any>. - runWithRequestState(), getCurrentRequestState() (throws), hasRequestState(), getRequestStateAsyncLocalStorage(). - defineRequestState(schema) for typed get/set. - Auth endpoints ensure a per-call request state and reuse when available. - OAuth middleware exposes getOauthState; set is internal to the flow. - OAuth: advanced.oauthConfig.additionalData { enabled?, schema?: StandardSchemaV1 } to validate and store data in request state. - signInSocial, generic OAuth, and linkSocialAccount accept additionalData; forwarded and available in hooks (not stored in DB). <sup>Written for commit ae7fccda44f2e8379f5c3e11cbd5779e5a39e783. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:28:33 -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#14439