Question

Firebase Auth user exists but Firestore profile document is missing

Solved · 5 views · asked by sven_fire · edited

Sometimes a user signs up and their users/{uid} document is never created. Then the app shows a blank profile and crashes on profile.name.

What I’ve tried

The document is created in the frontend right after createUserWithEmailAndPassword. Works 95% of the time.

Comment

1 answer

Marked as helpful by the asker
sven_fire · edited

That 5% is people closing the tab, losing network, or a rule rejecting the write between the two calls. Two calls from the client can never be atomic.

Move the creation server-side: a Cloud Function on auth.user().onCreate that writes the document. It runs even if the tab is gone. And in the app, treat a missing profile as "still creating", not as a crash.

Comment