Skip to content

useUser initial value null within AuthCheck children  #155

@cdock1029

Description

@cdock1029

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.

options ? options.startWithValue : undefined

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions