Reputation: 1697
I'm using FirebaseUI
and I want to store users in Firebase Authentication and MySQL together, How can I guarantee that will be added in both? Because maybe the user will be added in Firebase Authentication but during add user to MySQL the user leaves the app or lost connection etc...
How can I handle this scenario in a good way?
Upvotes: 0
Views: 549
Reputation: 599101
The most certain way is probably to do this from Cloud Functions, which can be triggered when the user is created. In that Cloud Functions code you then connect to your database and write the information about that user.
The main problem here is that you can only write very basic information about the user at that point, as the Cloud Function is called quite early in the process, so there's not a lot of information available.
If this is not enough for your use-case, the idiomatic approach is to check whenever the app starts whether the user profile in your database is complete, and if not, direct the user to the registration page. This approach means that in your scenario of them being disconnected, they will be asked to complete their registration when they restart the app.
A combination of both of these approach is also possible of course, as they nicely complement each other as long as you use the UID of the user as the primary key in the database.
Upvotes: 1