firebase / firebase/firebase-tools

user persistence in auth database in between `beforeCreate` and `beforeSignIn` is different in emulator and production

Open
#5,426 5 comments 3 reactions 1 assignee Assigned to @yuchenshi View on GitHub
emulators: auth type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

Reference: https://github.com/firebase/firebase-tools/issues/5327#issuecomment-1370172541

Current behaviour:
Suppose I set some persistent claims in `beforeCreate` blocking function.
After that, inside `beforeSignIn` blocking function, if I use `getAuth().getUser(user.uid)`, it will work in the emulator, but not in production.
As the referenced comment notes: In the emulator, the user is persisted to the db in-between the function calls; whereas in production, auth waits for all the blocking functions to complete before it persists the user to the db.

IMO, it would be best that the production behavior matches the emulator behavior and makes writes in-between the function calls. But in case it's not a feasible option to implement that, this difference should at least be mentioned clearly in the documentation of the blocking functions. Because there is no way to catch this bug a dev can ignorantly introduce until after the code is running in production - which is what happened with me. And even after watching the cloud logs, and redeploying multiple times, I was left with the question - "but it works fine on my local pc, so where's the problem?"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.