Firebase Authentication - When I login with signInWithUserEmailAndPassword, and then listen on the method onAuthStateChanged to get the 'user' object. In a React app, I set this to a useState variable. How do I make sure that a user does not have to login again when they visit the page again?
Below is a sample code snippet, this runs each time user starts the app / refreshes the page. However, if the app is deployed on a server, then how would this user remain logged in so that when they close the browser / restart the computer, the below code snipped passes through to get to the menu route?
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setCurrentUser(user);
if (user !== null) {
navigate("/menu");
}
});
return unsubscribe;
}, []);