From 285d808ce7487b16c7f45aa3732ca72adbee45ce Mon Sep 17 00:00:00 2001 From: solderq35 Date: Tue, 2 Apr 2024 17:29:52 -0700 Subject: [PATCH] move if statement up --- context/Auth.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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 (