Reputation: 2070
I have my app set up so that users can use it without logging in. This includes being able to save data. Each device/browser tuple generates a new anonymous user account for storing data.
I'm in the process of adding (facebook) login so that users can make sure their data persists across browsers and devices.
The firebase documentation shows how to handle a case where a user tries to link their account from multiple anonymous accounts and recommends an approach for merging data:
https://firebase.google.com/docs/auth/web/account-linking
My problem with this approach is that it deletes the original account that was linked which essentially boots the first account out of it's logged in state.
Imagine this flow for a single user:
I've implemented a different process which doesn't result in device A being booted, and instead logs device B into the account generated on device A. My problem with this flow is that I can't delete the user data from device B once I've successfully logged in to device A because I'm using access control rules on firebase so that user data may only be modified by the logged-in user who it belongs to.
potential (suboptimal) solutions:
I'm confused as to why the example in firebase docs seems to have this glaring issue and wondering what the best practice for this situation is.
Upvotes: 3
Views: 192
Reputation: 2070
I got no responses, but I implemented what I find to be an "elegant enough" solution to the problem.
Instead of deleting the prevUser
's account & data after succesful login to the other account, I just delete the account:
I implemented a firebase function to handle the deletion of the orphaned user data:
Upvotes: 2