Skip to content

Commit f23aa22

Browse files
committed
Authcontroller initialization tweak
1 parent 4e189f5 commit f23aa22

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/firebase_firecms/src/hooks/useFirebaseAuthController.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ export const useFirebaseAuthController = <ExtraData>({
5656

5757
const authRef = useRef(firebaseApp ? getAuth(firebaseApp) : null);
5858

59-
const updateUser = useCallback(async (user: FirebaseUser | null) => {
59+
const updateUser = useCallback(async (user: FirebaseUser | null, initialize?: boolean) => {
6060
if (loading) return;
6161
if (defineRolesFor && user) {
6262
const userRoles = await defineRolesFor(user);
6363
setRoles(userRoles);
6464
}
6565
setLoggedUser(user);
66-
setInitialLoading(false);
6766
setAuthLoading(false);
67+
if (initialize) {
68+
setInitialLoading(false);
69+
}
6870
}, [loading]);
6971

7072
useEffect(() => {
@@ -73,12 +75,12 @@ export const useFirebaseAuthController = <ExtraData>({
7375
const auth = getAuth(firebaseApp);
7476
authRef.current = auth;
7577
setAuthError(undefined);
76-
updateUser(auth.currentUser)
78+
updateUser(auth.currentUser, false)
7779
return onAuthStateChanged(
7880
auth,
79-
(user) => {
81+
async (user) => {
8082
console.log("User state changed", user);
81-
updateUser(user);
83+
await updateUser(user, true);
8284
},
8385
error => setAuthProviderError(error)
8486
);
@@ -92,7 +94,7 @@ export const useFirebaseAuthController = <ExtraData>({
9294

9395
useEffect(() => {
9496
if (!loading && authRef.current) {
95-
updateUser(authRef.current.currentUser);
97+
updateUser(authRef.current.currentUser, false);
9698
}
9799
}, [loading, updateUser]);
98100

0 commit comments

Comments
 (0)