-
Notifications
You must be signed in to change notification settings - Fork 404
Description
Version info
React: 16.10.2
Firebase: 7.2.9
ReactFire: 2.0.0-alpha.2
Other (e.g. Node, browser, operating system) (if applicable):
Test case
https://codesandbox.io/s/competent-mendeleev-svfjb
Steps to reproduce
Use AuthCheck with fallback login page.
Login in.
In "authorized" child component, call useUser
Access properties of user without checking for null.
Expected behavior
Since AuthCheck children won't render until user is logged in (not null), I'd expect all rendered descendant components under AuthCheck to have access to a not null user.
Actual behavior
Because of how useUser instantiates a new observable for every separate usage, there will always be an initial null value. Ideally, we wouldn't have to check for this everywhere in a component tree rendered after AuthCheck has a user.
I don't see the use case for having an optional startWith parameter in useUser instead of defaulting to app.auth().currentUser and not have to pass in ourselves everywhere.
reactfire/reactfire/auth/index.tsx
Line 41 in 99dac6c
| options ? options.startWithValue : undefined |