Skip to content

Commit 250aa37

Browse files
committed
Merge branch 'main' into fix/409-already-connected
2 parents 4f8976c + 8109cfe commit 250aa37

5 files changed

Lines changed: 57 additions & 18 deletions

File tree

docs/development/feature-file-map.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Use this document to find the first files to inspect for common Compass changes.
1616

1717
- Session initialization and SuperTokens wiring: `packages/web/src/auth/session/SessionProvider.tsx`
1818
- User profile bootstrap: `packages/web/src/auth/context/UserProvider.tsx`
19-
- Google OAuth app flow: `packages/web/src/auth/hooks/oauth/useGoogleAuth.ts`, `packages/web/src/auth/hooks/oauth/useGoogleAuthWithOverlay.ts`
20-
- Google OAuth provider wrapper: `packages/web/src/components/oauth/google/useGoogleLogin.ts`
19+
- Google OAuth app flow: `packages/web/src/auth/hooks/google/useGoogleAuth/useGoogleAuth.ts`, `packages/web/src/auth/hooks/google/useGoogleAuthWithOverlay/useGoogleAuthWithOverlay.ts`
20+
- Google OAuth provider wrapper: `packages/web/src/auth/hooks/google/useGoogleLogin/useGoogleLogin.ts`
2121
- Popup-cancel classification for Google OAuth: `packages/web/src/auth/google/google-oauth-error.util.ts`
2222
- Auth schemas: `packages/web/src/auth/schemas/auth.schemas.ts`
2323
- Backend auth routes: `packages/backend/src/auth/auth.routes.config.ts`
@@ -63,7 +63,7 @@ Use this document to find the first files to inspect for common Compass changes.
6363
- Sidebar shell and tab rendering: `packages/web/src/views/Calendar/components/Sidebar/Sidebar.tsx`
6464
- Footer icon row actions (tasks/month, command palette, sync/update): `packages/web/src/views/Calendar/components/Sidebar/SidebarIconRow/SidebarIconRow.tsx`
6565
- Sidebar layout constants and icon group styling: `packages/web/src/views/Calendar/components/Sidebar/styled.ts`
66-
- Google connection/status UI contract for sidebar + command palette: `packages/web/src/auth/hooks/oauth/useConnectGoogle.ts`
66+
- Google connection/status UI contract for sidebar + command palette: `packages/web/src/auth/hooks/google/useConnectGoogle/useConnectGoogle.ts`
6767
- Sidebar icon row behavior tests: `packages/web/src/views/Calendar/components/Sidebar/SidebarIconRow/SidebarIconRow.test.tsx`
6868

6969
## Offline Storage

docs/development/troubleshoot.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,26 @@ Operational notes:
8585
- UI should transition to reconnect-required behavior rather than repeatedly
8686
retrying repair
8787
- user action is to reconnect Google, then allow sync/import restart
88+
89+
## Google Connect Aborts With Local Events Sync Error
90+
91+
When a password-authenticated user connects Google from an existing session, the
92+
client now attempts to sync IndexedDB-only Compass events **before**
93+
`POST /api/auth/google/connect`.
94+
95+
If that pre-connect local sync fails, connect is intentionally aborted and the
96+
user sees:
97+
98+
- `We could not sync your local events. Your changes are still saved on this device.`
99+
100+
What this means operationally:
101+
102+
- this is a local-to-cloud event migration failure, not an OAuth popup failure
103+
- backend `connectGoogleToCurrentUser` is not called for that attempt
104+
- no Google import restart should be observed from that click
105+
106+
Recommended triage:
107+
108+
1. inspect browser console/network for the local event sync request failure
109+
2. resolve connectivity/auth issues to Compass APIs first
110+
3. retry Google connect after local sync succeeds

docs/features/google-sync-and-websocket-flow.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Important server-to-client events:
2525
Source files:
2626

2727
- `packages/core/src/types/websocket.types.ts`
28-
- `packages/backend/src/user/services/user.service.ts`
2928
- `packages/backend/src/sync/services/sync.service.ts`
3029

3130
`IMPORT_GCAL_END` now carries an explicit `operation` so the client can distinguish
@@ -282,17 +281,23 @@ When a user authenticates with email/password first and connects Google later
282281
from an existing session:
283282

284283
1. the web client completes the Google popup flow
285-
2. `useConnectGoogle()` sends the auth-code payload to
286-
`POST /api/auth/google/connect`
287-
3. backend `connectGoogleToCurrentUser()` attaches Google credentials to the
284+
2. `useConnectGoogle()` first calls `syncPendingLocalEvents(dispatch)` so
285+
IndexedDB-only Compass events are pushed before any Google refresh
286+
3. if local sync fails, connect is aborted and the user sees:
287+
- `We could not sync your local events. Your changes are still saved on this device.`
288+
4. on successful local sync, `useConnectGoogle()` sends the auth-code payload
289+
to `POST /api/auth/google/connect`
290+
5. backend `connectGoogleToCurrentUser()` attaches Google credentials to the
288291
existing Compass user
289-
4. backend marks sync metadata as `"RESTART"`
290-
5. background import/watch sync is restarted
292+
6. backend marks sync metadata as `"RESTART"`
293+
7. background import/watch sync is restarted
291294

292295
Operational constraints:
293296

294297
- this path no longer depends on SuperTokens `AccountLinking`
295298
- Google-account ownership is checked server-side by `google.googleId`
299+
- connect is intentionally blocked when local event sync fails; this prevents
300+
local-only Compass events from disappearing during Google-triggered refresh
296301
- restart still follows the same metadata/socket lifecycle
297302
(`IMPORT_GCAL_START`, metadata transitions, `IMPORT_GCAL_END`)
298303

@@ -302,7 +307,8 @@ Primary files:
302307
- `packages/backend/src/auth/services/google/google.auth.service.ts`
303308
- `packages/backend/src/auth/controllers/auth.controller.ts`
304309
- `packages/web/src/auth/google/google.auth.state.ts`
305-
- `packages/web/src/auth/hooks/oauth/useConnectGoogle.ts`
310+
- `packages/web/src/auth/google/google.auth.util.ts`
311+
- `packages/web/src/auth/hooks/google/useConnectGoogle/useConnectGoogle.ts`
306312
- `packages/web/src/common/repositories/event/event.repository.util.ts`
307313

308314
### Connect-Later Ownership Conflict Triage
@@ -390,7 +396,7 @@ Google import progress is also realtime:
390396
Source files:
391397

392398
- `packages/web/src/socket/hooks/useGcalSync.ts`
393-
- `packages/web/src/auth/hooks/oauth/useConnectGoogle.ts`
399+
- `packages/web/src/auth/hooks/google/useConnectGoogle/useConnectGoogle.ts`
394400
- `packages/web/src/ducks/events/slices/sync.slice.ts`
395401

396402
`IMPORT_GCAL_END` handling is operation-aware:

docs/frontend/frontend-runtime-flow.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ When a user re-authenticates with Google, auth-state utilities also clear any in
7777

7878
Files:
7979

80-
- `packages/web/src/auth/hooks/oauth/useGoogleAuth.ts`
81-
- `packages/web/src/components/oauth/google/useGoogleLogin.ts`
80+
- `packages/web/src/auth/hooks/google/useGoogleAuth/useGoogleAuth.ts`
81+
- `packages/web/src/auth/hooks/google/useGoogleLogin/useGoogleLogin.ts`
8282
- `packages/web/src/auth/google/google-oauth-error.util.ts`
8383

8484
The web auth flow intentionally treats popup-close outcomes as cancellation, not authentication failure.
@@ -134,7 +134,7 @@ Files:
134134
- `packages/web/src/views/Calendar/components/Sidebar/Sidebar.tsx`
135135
- `packages/web/src/views/Calendar/components/Sidebar/SidebarIconRow/SidebarIconRow.tsx`
136136
- `packages/web/src/views/Calendar/components/Sidebar/styled.ts`
137-
- `packages/web/src/auth/hooks/oauth/useConnectGoogle.ts`
137+
- `packages/web/src/auth/hooks/google/useConnectGoogle/useConnectGoogle.ts`
138138

139139
Layout contract:
140140

@@ -330,7 +330,8 @@ Runtime nuances:
330330

331331
Files:
332332

333-
- `packages/web/src/auth/hooks/oauth/useConnectGoogle.ts`
333+
- `packages/web/src/auth/hooks/google/useConnectGoogle/useConnectGoogle.ts`
334+
- `packages/web/src/auth/google/google.auth.util.ts`
334335
- `packages/web/src/views/Calendar/components/Sidebar/SidebarIconRow/SidebarIconRow.tsx`
335336

336337
UI state comes from a single server-enriched metadata field (`google.connectionState`) plus one client-only loading state:
@@ -346,6 +347,15 @@ Important constraint:
346347

347348
- `connectionState` values are uppercase string literals shared with backend/core (`NOT_CONNECTED`, `RECONNECT_REQUIRED`, `IMPORTING`, `HEALTHY`, `ATTENTION`); lowercase variants will not match UI state guards.
348349

350+
Connect-later guardrail:
351+
352+
- In the password-session "connect Google" flow, `useConnectGoogle` calls
353+
`syncPendingLocalEvents(dispatch)` before `AuthApi.connectGoogle(...)`.
354+
- If local sync fails, connect is aborted and a toast is shown:
355+
`"We could not sync your local events. Your changes are still saved on this device."`
356+
- This prevents IndexedDB-only Compass events from disappearing during the
357+
Google-triggered metadata/import refresh.
358+
349359
## What To Read Before Editing
350360

351361
- Auth/session issue: read session provider, user provider, router loaders.

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13148,9 +13148,9 @@ __metadata:
1314813148
linkType: hard
1314913149

1315013150
"path-to-regexp@npm:~0.1.12":
13151-
version: 0.1.12
13152-
resolution: "path-to-regexp@npm:0.1.12"
13153-
checksum: 10c0/1c6ff10ca169b773f3bba943bbc6a07182e332464704572962d277b900aeee81ac6aa5d060ff9e01149636c30b1f63af6e69dd7786ba6e0ddb39d4dee1f0645b
13151+
version: 0.1.13
13152+
resolution: "path-to-regexp@npm:0.1.13"
13153+
checksum: 10c0/1cae3921739c154a8926e136185a10c916f79a249b9072a5001b266d96e193860ca03867e8e8cc808b786862d750f427ed93686bc259355442c3407a62deab1a
1315413154
languageName: node
1315513155
linkType: hard
1315613156

0 commit comments

Comments
 (0)