Skip to content

fix(oauth): redirect on associate-callback errors instead of rendering JSON - #46

Merged
amrtgaber merged 1 commit into
mainfrom
fix/associate-callback-redirect-on-error
May 27, 2026
Merged

fix(oauth): redirect on associate-callback errors instead of rendering JSON#46
amrtgaber merged 1 commit into
mainfrom
fix/associate-callback-redirect-on-error

Conversation

@amrtgaber

Copy link
Copy Markdown
Contributor

Summary

  • Wraps /auth/<provider>/associate/callback so any HTTPException whose detail carries a code becomes a 302 to {frontend_url}/profile?associate_error=<code>&associate_provider=<provider> instead of raw JSON.
  • A tester linking a Steam account that was already attached to another user hit oauth_account_already_linked and got the raw JSON detail rendered as the entire page — because in prod Steam/Google redirect the browser directly to this endpoint (no SPA layer in front of it).
  • Exceptions without a structured code re-raise so we don't accidentally swallow unrelated errors.

Companion PR

The SPA-side rendering of the alert lives in ag-tech-group/criticalbit-auth-web#TBD — should land together. This PR alone makes the URL stop showing JSON; both together make it look like a proper alert.

Test plan

  • uv run pytest — 130 passed, 1 skipped
  • State-validation tests in test_provider_associate.py updated to assert the new redirect shape (/profile?associate_error=<code>&associate_provider=steam) for: oauth_state_missing, oauth_state_wrong_purpose, oauth_state_user_mismatch, oauth_csrf_mismatch, and the 409 oauth_account_already_linked conflict path.
  • Manual: in dev, sign in, attempt to link a Steam ID already attached to another user → browser ends up at /profile?associate_error=oauth_account_already_linked&associate_provider=steam (the SPA PR handles the alert from there).

…g JSON

When the provider redirects the browser directly to /auth/<provider>/associate/callback
(prod) and the handler raises HTTPException, FastAPI surfaces the raw JSON
to the user — most visibly oauth_account_already_linked, which a tester hit
when re-linking a Steam account already attached to another user.

Wrap the handler so any HTTPException whose detail carries a `code` becomes
a 302 to {frontend_url}/profile?associate_error=<code>&associate_provider=<provider>.
The SPA renders the message as a proper alert from there (separate PR).
Exceptions without a structured code re-raise so we don't accidentally
swallow unrelated errors.

Updated the state-validation and conflict tests to assert the redirect
shape instead of JSON.
@amrtgaber
amrtgaber merged commit 6b0f68e into main May 27, 2026
2 checks passed
@amrtgaber
amrtgaber deleted the fix/associate-callback-redirect-on-error branch May 27, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant