Demo, all content is generated
Question

Firebase Auth user exists but Firestore profile document is missing

Solved · 288 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
Is the profile write awaited? We saw exactly this when it was fire-and-forget after signup. lukas_b · edited

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
One gotcha with the onCreate trigger: it can finish after the client already tried to read the profile. Show a loading state or retry once. kofi_mensah · edited