diff --git a/context/Auth.js b/context/Auth.js index 7860f36f..5af5d67a 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -45,23 +45,21 @@ export const AuthProvider = ({ children }) => { useEffect(() => { //if this code is not in here, it'll run for infinite times onAuthStateChanged(auth, (currentUserId) => { - // keep this log outside if statement to confirm e.g. logout of test user console.log("user changed"); - // prevent "persistent login" of regular user login from conflicting with test user - if (!process.env.EXPO_PUBLIC_TEST_UID) { + // test user login (yarn test) + // If you sign out, reload app to sign back in as test user + if (process.env.EXPO_PUBLIC_TEST_UID) { + setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); + } + + // regular user login + else { if (currentUserId) { setCurrentUserId(currentUserId.uid ?? "Error (uid)"); } } }); - - // yarn test - // If you sign out, reload app to sign back in as test user - // Moved outside of onAuthChanged to avoid race condition with logout - if (process.env.EXPO_PUBLIC_TEST_UID) { - setCurrentUserId(process.env.EXPO_PUBLIC_TEST_UID); - } }, []); return (