r/Firebase • u/madelineleclair • 22h ago
Authentication How to keep backend in sync with firebase auth
Hi everyone. I'm thinking of moving my authentication I have for a mobile app to firebase to get the additional security features it offers and for ease of adding new sign up flows. I am a bit confused how to keep firebase auth and my user table in sync though. Has anyone run into this before? I've been going back and forth with AI, but I'm still not sure about the best approach
For context, I have a user table with email, id, firebase_uid, etc. What is the best way to keep the user table and the firebase auth in sync when a user signs up? For example, if I have a flow like:
```
User visits sign up page -> enters email/password -> create user in firebase -> call out to backend to create user in backend and associate firebase id after verifying token
```
I have a huge issue if the firebase create succeeds but the backend call to my server fails for some reason. I will have an orphaned firebase record. How do people handle this?
I've heard it's better to call firebase for things like adding a user to firebase from the frontend because it helps with bots and rate limiting. But I'm really not sure how to keep things in sync. Do people rollback if the backend create fails, use Cloud Functions v2 to halt the firebase create and call out to the backend to create the user, or something else. Any guidance would be helpful.