Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Improve logout behavior

Open b-straub opened this issue 1 year ago • 2 comments

Suggestions to improve logout behavior (version 4.0.7)

  • Try to push changes when any and not just indicate unsynced changes in "not force" mode.
  • Improve logout sync behavior.

https://github.com/dexie/Dexie.js/blob/795f60c8104317f3b2d9ddcd0c20c84fb74fe83e/addons/dexie-cloud/src/authentication/logout.ts#L62

when not online an 'error in syncIfPossible()' exception will be thrown here https://github.com/dexie/Dexie.js/blob/795f60c8104317f3b2d9ddcd0c20c84fb74fe83e/addons/dexie-cloud/src/sync/syncIfPossible.ts#L93 but not propagated upstream in order to catch and inform user that logout is not possible.

  • I worked around both issues client side, bu having something working out of the box would be nicer.

b-straub avatar Jun 21 '24 09:06 b-straub

Thanks!

Basically a logout should be a client action only - it deletes the database and then tries to do an initial sync based on anonymous user to get schema and public data in sync. If this sync fails, user is still technically logged out but hasn't got public data from the server yet. But as soon as the app goes online again it should do the initial sync.

Is the bug happening when client is offline, there are unsynced changes, and user choose to log out? Does it leave the db in a buggy state?

dfahlander avatar Jun 25 '24 23:06 dfahlander

  • I have a solution for my request #1986, which requires writing some database entries when the user is about to log out. Actually I could solve this client side, but when inspecting the cloud add-on code, I thought it would be nice to push any pending changes before the actual logout. This may be necessary if a table write is immediately followed by the logout request.
  • In fact, the bug happens when offline. Again, this could be solved client-side, but I think it might be good practice not to block an asynchronous operation when a potentially valid state occurs. I suggest propagating the described error upstream to catch and inform the user.

b-straub avatar Jun 26 '24 10:06 b-straub