fix(web): show account linking before OAuth consent
Fixes SOU-2270
OAuth authorization now shows the account-linking screen before consent, using the same AccountLinkingGuard as the main app. Login and account linking return to the original authorization request with its parameters preserved, including repeated parameters.
Optional-provider dismissals now remember provider IDs, so newly configured optional providers prompt again while previously skipped providers stay dismissed. Required providers always prompt while unlinked. Legacy boolean skip cookies cause a one-time re-prompt.
Validation: 37 relevant tests passed, targeted ESLint passed, and git diff --check passed. TypeScript reports only existing generated Next.js settings-route errors. A live GitHub OAuth round trip was not exercised.
[!NOTE]
Medium Risk
Touches OAuth authorization and SSO account-linking gates, which affect who can complete OAuth and when consent is shown; behavior is well covered by new tests but still auth-critical.
Overview
OAuth authorization now enforces account linking before consent, using a shared AccountLinkingGuard instead of inline logic in the app layout. The guard wraps both the main app shell and /oauth/authorize, and returns users to the original URL (including repeated query params via getOAuthAuthorizeUrl) after login or linking.
Optional-provider “Skip for now” is tracked per provider ID in a JSON cookie (legacy boolean values are ignored), so newly added optional providers prompt again while previously skipped ones stay dismissed; required unlinked providers cannot be skipped. ConnectAccountsCard passes only the optional unlinked provider IDs when skipping.
OAuth authorize flow checks org membership before linking/consent and redirects users without active or pending membership to /. Tests cover guard behavior, OAuth resume, and skip cookie semantics.
Reviewed by Cursor Bugbot for commit f84ab547143c88ee5e6bc8ce02c84f394ce58d2a. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes SOU-2270 by showing the account-linking screen before OAuth consent. The /oauth/authorize route now uses the same AccountLinkingGuard as the main app, so required or unskipped optional providers prompt before the consent screen.
- Login and account linking resume the original authorization request with repeated query parameters preserved.
- OAuth users without an active or pending org membership are redirected home before account linking or consent runs.
- Optional-provider skips are stored per provider ID, so newly configured optional providers prompt again while previously skipped providers stay dismissed.
- Legacy boolean skip cookies cause a one-time re-prompt; required providers always prompt while unlinked.
Summary by CodeRabbit
- Bug Fixes
- Restored account-linking prompts for Enterprise users during OAuth authorization.
- OAuth requests now resume correctly after required account linking and preserve repeated parameters.
- Optional-provider prompts reappear when newly configured providers require attention.
- “Skip for now” selections are preserved per provider without suppressing future prompts.
- Invalid or outdated skip settings are safely ignored.
- Users without an active or pending membership are redirected home during OAuth authorization.
- Tests
- Added comprehensive coverage for OAuth authorization and account-linking behavior.
- Documentation
- Updated the unreleased changelog with these fixes.