[PR #7092] [CLOSED] Fixes #6613 - oauth-provider missing request state #7069

Closed
opened 2026-03-13 13:23:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7092
Author: @zackliscio
Created: 1/2/2026
Status: Closed

Base: canaryHead: fix/oauth-provider-serverless-guard


📝 Commits (10+)

  • 197e88d feat: add ctx.isTrustedDomain helper (#6462)
  • 233b18b chore: hoist endpoint schemas (#6283)
  • 2865473 docs(jwt): remove JWT adapter getLatestKey (#6511)
  • 015a5c4 chore: async local storage fallback for convex (#6534)
  • 8704191 chore: remove unused exports and export types (#6513)
  • be00f10 fix(openapi): mark /get-session response as nullable (#6540)
  • f053d5c docs: clarify createOrganization behavior regarding userId and session headers (#6526)
  • 816f19d fix(saml): enforce trusted provider check (#6551)
  • 1f1ff79 docs: correct API component usage (#6556)
  • a501b08 fix(cli): deduplicate drizzle schema relationships (#6547)

📊 Changes

3 files changed (+121 additions, -3 deletions)

View changed files

📝 docs/content/docs/plugins/dodopayments.mdx (+108 -2)
📝 docs/content/docs/plugins/sso.mdx (+7 -0)
📝 packages/oauth-provider/src/oauth.ts (+6 -1)

📄 Description

Description

This PR fixes an issue where the oauth-provider plugin would throw an error in serverless environments (like Cloudflare Workers or AWS Lambda) when the AsyncLocalStorage request state is missing during the after hook execution.

The after hook runs on every request that sets a session cookie, including non-OAuth flows. In some serverless contexts, oAuthState.get() would fail because the request state context wasn't initialized for those non-OAuth requests.

Changes

Closes #6613

Verification

  • Ran all tests in packages/oauth-provider (pnpm test) - All 139 tests passed.
  • Ran pnpm lint:package - Passed.
  • Ran pnpm typecheck - Passed.

Summary by cubic

Fixes a crash in oauth-provider on serverless platforms by skipping the after hook when the request state isn’t available. This prevents errors on non-OAuth requests that set session cookies and improves stability in environments like Cloudflare Workers and AWS Lambda. Fixes #6613.

  • Bug Fixes
    • Added a guard in oauth-provider’s after hook to skip execution when hasRequestState() is false.
    • Ensured oauth-provider requires session.storeSessionInDatabase: true when using secondary storage to support provider flows.
    • Standardized JWKS URL construction to respect a custom jwksPath across endpoints.

Written for commit c2d634c378. 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/7092 **Author:** [@zackliscio](https://github.com/zackliscio) **Created:** 1/2/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/oauth-provider-serverless-guard` --- ### 📝 Commits (10+) - [`197e88d`](https://github.com/better-auth/better-auth/commit/197e88dd0de87def3f8ef637847cfae1de742c1a) feat: add `ctx.isTrustedDomain` helper (#6462) - [`233b18b`](https://github.com/better-auth/better-auth/commit/233b18b11d6b6a5832bf2673b6deb30ba6f78b17) chore: hoist endpoint schemas (#6283) - [`2865473`](https://github.com/better-auth/better-auth/commit/28654734e13dc0bb22d5623722e97b9a8dbc1b37) docs(jwt): remove JWT adapter `getLatestKey` (#6511) - [`015a5c4`](https://github.com/better-auth/better-auth/commit/015a5c4b660b69f2a941ffd069ea831c8670a45d) chore: async local storage fallback for convex (#6534) - [`8704191`](https://github.com/better-auth/better-auth/commit/870419144c6e6621664a349b79b059456573b9b6) chore: remove unused exports and export types (#6513) - [`be00f10`](https://github.com/better-auth/better-auth/commit/be00f10cad5bbad5a0dababa4b836a3d95ce7747) fix(openapi): mark /get-session response as nullable (#6540) - [`f053d5c`](https://github.com/better-auth/better-auth/commit/f053d5c7719cabb9b4d5d26180ec1afa7e74d8dd) docs: clarify createOrganization behavior regarding userId and session headers (#6526) - [`816f19d`](https://github.com/better-auth/better-auth/commit/816f19dade33e553b3ef337c3efb651d0d6b979a) fix(saml): enforce trusted provider check (#6551) - [`1f1ff79`](https://github.com/better-auth/better-auth/commit/1f1ff790c44741fd0e87e0e653347284d4624e67) docs: correct API component usage (#6556) - [`a501b08`](https://github.com/better-auth/better-auth/commit/a501b0813c36e6b7a8ed55870985242d90e45b23) fix(cli): deduplicate drizzle schema relationships (#6547) ### 📊 Changes **3 files changed** (+121 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/dodopayments.mdx` (+108 -2) 📝 `docs/content/docs/plugins/sso.mdx` (+7 -0) 📝 `packages/oauth-provider/src/oauth.ts` (+6 -1) </details> ### 📄 Description ## Description This PR fixes an issue where the `oauth-provider` plugin would throw an error in serverless environments (like Cloudflare Workers or AWS Lambda) when the `AsyncLocalStorage` request state is missing during the `after` hook execution. The `after` hook runs on every request that sets a session cookie, including non-OAuth flows. In some serverless contexts, `oAuthState.get()` would fail because the request state context wasn't initialized for those non-OAuth requests. ## Changes - Added a guard `if (!(await hasRequestState())) return;` in the `after` hook of [packages/oauth-provider/src/oauth.ts](cci:7://file:///Users/zackliscio/cloudcapital/better-auth/packages/oauth-provider/src/oauth.ts:0:0-0:0) to skip execution if the request state is not available. ## Related Issues Closes #6613 ## Verification - [x] Ran all tests in `packages/oauth-provider` (`pnpm test`) - **All 139 tests passed**. - [x] Ran `pnpm lint:package` - **Passed**. - [x] Ran `pnpm typecheck` - **Passed**. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes a crash in oauth-provider on serverless platforms by skipping the after hook when the request state isn’t available. This prevents errors on non-OAuth requests that set session cookies and improves stability in environments like Cloudflare Workers and AWS Lambda. Fixes #6613. - **Bug Fixes** - Added a guard in oauth-provider’s after hook to skip execution when `hasRequestState()` is false. - Ensured oauth-provider requires `session.storeSessionInDatabase: true` when using secondary storage to support provider flows. - Standardized JWKS URL construction to respect a custom `jwksPath` across endpoints. <sup>Written for commit c2d634c3781b170e40283cb1f3c8645d14e411be. 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 13:23:02 -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#7069