Skip to content

Commit

Permalink
move if statement up
Browse files Browse the repository at this point in the history
  • Loading branch information
solderq35 committed Apr 3, 2024
1 parent 18490bd commit 285d808
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions context/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<AuthContext.Provider
Expand Down

0 comments on commit 285d808

Please sign in to comment.