feat(web): use sync redirect flow for Google connect when delegated#2355
Merged
Conversation
When the deployment delegates Google connections to the sync service (google.connectDelegatedToSync on /api/config), the connect action now asks the backend for the provider consent URL via POST /api/auth/google/connect/begin and navigates the browser there, instead of the legacy client-side code-exchange popup flow. Legacy stays the default whenever the flag is false or unknown. - AuthApi.beginGoogleConnection(): POST /auth/google/connect/begin. - useIsConnectDelegatedToSync(): reads the flag from the same /config fetch that drives Google availability (single source of truth). - useConnectGoogle branches on it; begin failure shows an error toast. Co-Authored-By: Claude Opus 4.8 <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.
What
Completes web connect-delegation for Compass Sync (S38). When a deployment delegates Google connections to the sync service, the "connect Google Calendar" action now uses the redirect flow instead of the legacy client-side code-exchange:
POST /api/auth/google/connect/begin→{ authorizationUrl }window.location.assign(authorizationUrl)— the sync service owns the OAuth round-trip and its own callback.The browser learns the deployment posture from
google.connectDelegatedToSynconGET /api/config(merged in #2354).Legacy stays the default whenever the flag is
falseor not-yet-loaded, so existing deployments are unchanged.How
AuthApi.beginGoogleConnection()—POST /auth/google/connect/begin, parsesConnectionBeginResponse.useIsConnectDelegatedToSync()— reads the flag from the same/configfetch that already drives Google availability (single source of truth, no extra network call).useConnectGooglebranches on the flag; abeginfailure shows an error toast and does not navigate.Fail-safe design
falseuntil/configresolves, and by the time the connect button is available the config has loaded (availability is gated on the same fetch). So the flag is accurate at click time, and any race falls back to legacy.connectCalendar, already-authenticated) is affected. Sign-in is untouched.Deployment prerequisites (for when delegation is actually switched on)
/oauth/google/callbackmust be publicly reachable by Google.beginreturns 409 in passive mode).Neither blocks this PR — the redirect flow is dormant until
SYNC_CONNECTION_ROUTING=sync.Testing
useIsConnectDelegatedToSynctests: flag reflected from config; stays legacy when the field is absent (older backend).bun test src/auth/google/ src/components/CommandPalette/→ 109 pass.bun run type-check: zero new errors vsorigin/main(set-difference against pre-existing local baseline).Manual Testing Steps
/api/config→connectDelegatedToSync: false): connect Google → legacy popup/code flow (unchanged).connectDelegatedToSync: true): connect Google → browser navigates to the sync-minted consent URL.🤖 Generated with Claude Code
Note
Medium Risk
OAuth connect behavior changes for delegated deployments; legacy remains the default until config confirms delegation, limiting blast radius.
Overview
When
google.connectDelegatedToSyncis true on/api/config, Connect Google Calendar no longer runs the legacy popup/code-exchange flow. It callsPOST /auth/google/connect/begin, thenwindow.location.assign(authorizationUrl)so the sync service owns OAuth; failures show a dedicated error toast and do not navigate.useIsConnectDelegatedToSyncreads that flag from the same/configfetch as Google availability (defaults to false until loaded or if the field is missing).AuthApi.beginGoogleConnectionwraps the begin endpoint withConnectionBeginResponseparsing.Repair/sign-in paths are unchanged; only the authenticated connect action branches.
Reviewed by Cursor Bugbot for commit ce03bb6. Bugbot is set up for automated code reviews on this repo. Configure here.