Skip to content

fix: save events locally without active session#1664

Merged
Uarmagan merged 2 commits intomainfrom
bug/fix-stale-auth-local-event-save
Apr 22, 2026
Merged

fix: save events locally without active session#1664
Uarmagan merged 2 commits intomainfrom
bug/fix-stale-auth-local-event-save

Conversation

@Uarmagan
Copy link
Copy Markdown
Contributor

Summary

  • Use the local IndexedDB event repository whenever there is no active SuperTokens session.
  • Keep authenticated users on the remote repository when a session exists.
  • Add repository-selection coverage for active session, missing session, and Google-revoked fallback.

Why

A browser can keep compass.auth.hasAuthenticated=true from an older hosted/dev/self-host session even when the new local backend has no valid session. In that state, anonymous event creation was routed to the backend and failed with 401, causing the optimistic event to disappear. Without an active session, event writes should stay local.

Validation

  • Rebuilt the local self-host install with this change.
  • Reproduced stale auth state by setting localStorage.compass.auth.hasAuthenticated=true without a valid session.
  • Created a calendar event successfully; no POST /api/event request was sent.
  • bunx biome check packages/web/src/common/repositories/event/event.repository.util.ts packages/web/src/common/repositories/event/event.repository.util.test.ts
  • bun run test:core

Known: direct bun test --cwd packages/web ... still hits the existing web test harness global issue (jest / browser globals), unrelated to this change.

@Uarmagan Uarmagan force-pushed the bug/fix-stale-auth-local-event-save branch 3 times, most recently from 1117873 to 5a8d50e Compare April 22, 2026 21:13
Run the bundled MongoDB container as a single-node replica set so the backend's transaction-based event save path works in local self-host installs.

Update installer env generation and refresh handling to add the Mongo replica set key and ensure local Mongo URIs include replicaSet=rs0 without wiping existing user data.

Clean up failed optimistic event creates locally instead of calling the backend delete endpoint for events that were never saved, avoiding a misleading login-required alert after save failures.
@Uarmagan Uarmagan force-pushed the bug/fix-stale-auth-local-event-save branch from 5a8d50e to 45e4ed2 Compare April 22, 2026 22:48
@Uarmagan Uarmagan merged commit 462fa94 into main Apr 22, 2026
6 of 8 checks passed
@Uarmagan Uarmagan deleted the bug/fix-stale-auth-local-event-save branch April 22, 2026 23:03
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