From 0236b043d8920f420fea0708fcc9bbc87f41a5a9 Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 28 May 2022 12:13:01 -0500 Subject: [PATCH] Update AuthProvider.tsx --- packages/desktop/src/providers/AuthProvider.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/desktop/src/providers/AuthProvider.tsx b/packages/desktop/src/providers/AuthProvider.tsx index d4c4d47..cfd2fbb 100644 --- a/packages/desktop/src/providers/AuthProvider.tsx +++ b/packages/desktop/src/providers/AuthProvider.tsx @@ -19,6 +19,8 @@ import { import { useSnackbar } from 'notistack'; import { createUser } from '../firebase/firestore'; +import CircularProgress from '@mui/material/CircularProgress'; + interface IAuthContext { user?: FirebaseUser; logout?: () => void; @@ -32,6 +34,9 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { // since auth.currentuser isn't updating const [currentUser, setCurrentUser] = useState(null); + // are we still waiting on initial auth to trigger? + const [authIniting, setAuthIniting] = useState(true); + useEffect(() => { const authListener = onAuthStateChanged(firebaseAuth, async (user) => { console.log('auth changed!!!!', user); @@ -47,10 +52,12 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { enqueueSnackbar('Logged out'); setCurrentUser(null); } + + setAuthIniting(false); }); return () => authListener(); - }, [setCurrentUser, enqueueSnackbar]); + }, [setCurrentUser, enqueueSnackbar, setAuthIniting]); useEffect(() => { const tokenListener = window.electronAPI.once( @@ -95,6 +102,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { const logout = useCallback(() => firebaseAuth.signOut(), []); + if (authIniting) return ; return ( {currentUser ? <>{children} : }