Skip to content

Commit eb1428b

Browse files
authored
do not set initialdata if user is undefined (#521)
1 parent f3e54af commit eb1428b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/auth.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export function useUser<T = unknown>(options?: ReactFireOptions<T>): ObservableS
2424

2525
const observableId = `auth:user:${auth.name}`;
2626
const observable$ = user(auth);
27+
const _options: ReactFireOptions<T> = {...options} ?? {};
2728

28-
let currentUser = auth.currentUser;
29-
30-
// Only use options.initialData if auth.currentUser is unavailable
31-
if (!currentUser && (options?.initialData ?? options?.startWithValue)) {
32-
currentUser = options.initialData ?? options.startWithValue;
29+
// only set/override initialData if auth has finished loading
30+
if (auth.currentUser !== undefined) {
31+
_options.initialData = auth.currentUser;
32+
_options.startWithValue = auth.currentUser;
3333
}
3434

35-
return useObservable(observableId, observable$, { ...options, initialData: currentUser });
35+
return useObservable(observableId, observable$, _options);
3636
}
3737

3838
export function useIdTokenResult(user: User, forceRefresh: boolean = false, options?: ReactFireOptions<IdTokenResult>): ObservableStatus<IdTokenResult> {

0 commit comments

Comments
 (0)