Skip to content

Commit

Permalink
persistent state bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-Gu-81 committed Jan 23, 2025
1 parent 226b615 commit 20da5b4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ function App() {

useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (curUser) => {
setUser(curUser);
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
setUserEmail(curUser?.email);
setProfilePic(curUser?.photoURL);
setAuthLoaded(true);
if (curUser) {
setUser(curUser);
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
setUserEmail(curUser?.email);
setProfilePic(curUser?.photoURL);
setAuthLoaded(true);
} else {
setUser(null);
setUserEmail(null);
setProfilePic(null);
setAuthLoaded(true);
}
})

return () => unsubscribe();
Expand Down

0 comments on commit 20da5b4

Please sign in to comment.