fix: improve region handling in OAuth login flow and persistent cache#91
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
volnei
approved these changes
May 19, 2026
devin-ai-integration Bot
added a commit
that referenced
this pull request
May 19, 2026
PR #91 migrated the persisted cache to a region-suffixed key (`cal-companion-query-cache-{region}`). Users upgrading from before that change still have the pre-migration unsuffixed key (`cal-companion-query-cache`) on disk, which is now never read. Without cleanup, it lingers forever and the per-user expiry sweep never runs against it. Add a one-line removeItem for the legacy key inside restoreClient. Runs on every restore; removeItem on a missing key is a no-op so the cost after the first cleanup is negligible.
5 tasks
dhairyashiil
added a commit
that referenced
this pull request
May 19, 2026
* fix(auth): isolate user data across logout and cold-start transitions Eliminates cross-user data leaks in the mobile/web/extension app by plugging gaps in the logout cleanup and persisted-cache rehydration flow. - AuthContext.logout() now clears the in-memory QueryClient (A1) so the next login does not flash the previous user's userProfile, eventTypes, bookings, or schedules under staleTime: Infinity + refetchOnMount: false. - AuthContext.logout() now calls clearWidgetBookings() (A3) so the iOS / Android home-screen widget does not keep showing the signed-out user's meetings. - AuthContext.logout()'s clearAuth() step is wrapped in its own try/catch (A5) so a SecureStore failure no longer skips region/cache/widget cleanup and leaves a zombie session with isAuthenticated still true. - useWidgetSync no longer fires syncBookingsToWidget on mount when isAuthenticated is false (A6), preventing an unauthenticated /bookings fallback during cold start before tokens are loaded. - queryPersister.restoreClient checks for cal_oauth_tokens OR cal_auth_type before rehydrating (A2 pt 1); if neither is present the orphaned cache is wiped so a previously-logged-in user's data is never restored into a logged-out cold start. Checking both keys covers the web-session login path that writes cal_auth_type without OAuth tokens. - setupAfterLogin compares the rehydrated userProfile.id to the just- fetched profile and wipes both in-memory and persisted caches on a mismatch (A2 pt 2). * fix(persister): sweep pre-region-suffix cache key on every restore PR #91 migrated the persisted cache to a region-suffixed key (`cal-companion-query-cache-{region}`). Users upgrading from before that change still have the pre-migration unsuffixed key (`cal-companion-query-cache`) on disk, which is now never read. Without cleanup, it lingers forever and the per-user expiry sweep never runs against it. Add a one-line removeItem for the legacy key inside restoreClient. Runs on every restore; removeItem on a missing key is a no-op so the cost after the first cleanup is negligible. * fix(auth): drop stale user-profile singleton before post-login refetch CalComAPIService.getUserProfile() is backed by a module-level singleton (`_userProfile` in services/calcom/user.ts). If the JS context survives between logout and the next login — long-lived extension iframe, rapid re-login, or a future in-session account switch — the singleton can still hold the previous user's profile and getUserProfile() will hand it back without touching the API. The downstream identity-mismatch check would then see two matching ids and silently pass. Clearing the singleton between setAccessToken and getUserProfile forces a fresh fetch tied to the just-installed access token, so identity detection sees the true new-user profile. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.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 does this PR do?
Improves region handling across the OAuth login flow and the React Query persistent cache.
loginWithOAuthnow constructsCalComOAuthServicedirectly from the current region at call time instead of reading from React state, ensuring the correct OAuth endpoint is always used when the user logs in.The React Query persister storage key now includes the active region (
cal-companion-query-cache-us/cal-companion-query-cache-eu), scoping cached data per region.Also fixes
removeClientreferencing an undefined variable and replacesconsole.warnwithsafeLogWarn.Changes
utils/queryPersister.tsremoveClientreferencing an undefined variablecontexts/AuthContext.tsxCalComOAuthServicefrom current region atloginWithOAuthcall time instead of reading React stateHow should this be tested?
app.cal.euapp.cal.comMandatory Tasks