Skip to content

Commit

Permalink
fix(auth): only use currentUser as default if signed in
Browse files Browse the repository at this point in the history
Auth.currentUser is `null` during initialization. `useAuthState` therefore
returned `null` while firebase was still fetching the current state.
With this change, `useAuthState` never returns a wrong state while
firebase is still loading.
  • Loading branch information
andipaetzold committed Oct 20, 2021
1 parent 5de267c commit 3c9086d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/auth/useAuthState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe("initial state", () => {
expect(result.current).toStrictEqual([currentUser, false, undefined]);
});

it("should return undefined when currentUser is undefined", () => {
const mockAuth = {} as Auth;
it("should return undefined when currentUser is null", () => {
const mockAuth = { currentUser: null } as Auth;

onAuthStateChangedMock.mockImplementation(() => () => {});

Expand Down
2 changes: 1 addition & 1 deletion src/auth/useAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export function useAuthState(auth: Auth): UseAuthStateResult {
[]
);

return useListen(auth, onChange, () => true, auth.currentUser);
return useListen(auth, onChange, () => true, auth.currentUser ?? undefined);
}

0 comments on commit 3c9086d

Please sign in to comment.