Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue login without sync #1977

Merged
merged 2 commits into from
May 3, 2024
Merged

Issue login without sync #1977

merged 2 commits into from
May 3, 2024

Conversation

dfahlander
Copy link
Collaborator

@dfahlander dfahlander commented May 3, 2024

An issue was reported privately that the following situation could occur:

  1. Login prompt, enter email
  2. OTP prompt enter OTP
  3. Authentication happens
  4. Sync starts
  5. Web page is refreshed, aborting the sync call
  6. Now, state could be authenticated but without any data from the realms that the user have access to - only from the public realm. Refreshing page again did not help. Only explicitely calling db.cloud.sync({purpuse: "pull"}) could resolve the state and download all data for the user.

The issue was that in connectWebSocket.ts, createObservable(), in case user is logged in, we're waiting with setting up the websocket until the user's sync call has completeted. Now if page was refreshed after login, but before sync call completed, the webSocket will wait there forever. We still want to wait there in case user is logged in so that we don't setup a websocket subscribing to public data only and then realize the realms have changed and reconnect socket.

So the solution I made was in dexie-cloud-client.ts, to treat this in-between-state as if user has been changed and thus trigger a sync with purpose "pull" (which means it should sync regardless if we have local changes or not).

2nd commit: we also rewrite the deprecated .toPromise() method on Rx observables and use firstValueFrom() instead. We could also remove take(1) because firstValueFrom() will only take first emitted value anyway.

@dfahlander dfahlander merged commit 944e3fc into master May 3, 2024
5 checks passed
@dfahlander dfahlander deleted the issue-login-without-sync branch May 4, 2024 21:28
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.

None yet

1 participant