fix(auth): keep SSO working when the app and API are on different ori… - #1202
Open
njbrake wants to merge 1 commit into
Open
fix(auth): keep SSO working when the app and API are on different ori…#1202njbrake wants to merge 1 commit into
njbrake wants to merge 1 commit into
Conversation
…gins _Note: this PR description was drafted by Claude via back-and-forth with @njbrake. The reasoning and decisions are his; the prose is Claude's._ Fixes two SSO failures that only appear when the app and the API are served from different origins. Both are invisible in the Compose and ALB setups, where one origin proxies both. **Sign-in returns a bare `NOT_FOUND`.** Better Auth resolves its error redirect as `onAPIError.errorURL || ${baseURL}/error`, and `baseURL` is the API origin, which serves no HTML. Any auth failure lands on a blank 404 instead of the app. Now sets `onAPIError.errorURL` to `APP_URL`. **The OAuth state cookie is rejected.** `__Secure-better-auth.state` is set by the API origin and read back during a redirect initiated from the app origin, so a cross-site `SameSite=Lax` cookie is dropped and sign-in fails. `account.skipStateCookieCheck` is now enabled only when `APP_URL` and the backend origin actually differ, so single-origin deployments keep the check. PKCE still protects the exchange, and the state parameter is still round-tripped through the provider. The cookie is a second layer that a split-origin deployment cannot rely on. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…gins
Note: this PR description was drafted by Claude via back-and-forth with @njbrake. The reasoning and decisions are his; the prose is Claude's.
Fixes two SSO failures that only appear when the app and the API are served from different origins. Both are invisible in the Compose and ALB setups, where one origin proxies both.
Sign-in returns a bare
NOT_FOUND. Better Auth resolves its error redirect asonAPIError.errorURL || ${baseURL}/error, andbaseURLis the API origin, which serves no HTML. Any auth failure lands on a blank 404 instead of the app. Now setsonAPIError.errorURLtoAPP_URL.The OAuth state cookie is rejected.
__Secure-better-auth.stateis set by the API origin and read back during a redirect initiated from the app origin, so a cross-siteSameSite=Laxcookie is dropped and sign-in fails.account.skipStateCookieCheckis now enabled only whenAPP_URLand the backend origin actually differ, so single-origin deployments keep the check.PKCE still protects the exchange, and the state parameter is still round-tripped through the provider. The cookie is a second layer that a split-origin deployment cannot rely on.