I get logged out every-time I refresh, here's the code I am using. nothing special just simple conditional render in React.
What is causing this?
I tried using set persistence but that's giving errors.
export default function GAuth(){
const [currentUser, setCurrentUser] = useState(null);
let auth = getAuth();
let GoogleProvider = new GoogleAuthProvider()
function handleSubmit(event) {
event.preventDefault();
signInWithPopup(auth, GoogleProvider)
.then((response) => {setCurrentUser(response.user)})
.catch((err) => {alert(err.message)})
}
function authChecker(){
if(currentUser){
console.log("User is logged in")
return <FullApp/>
}else{
console.log("User is not logged in")
return (<div className="auth-page">
<form className="signup-form" onSubmit={handleSubmit}>
<h1>You have No Notes, Sign In to create one</h1>
<input className="first-note" type="submit" value={"Sign in with google"} />
</form>
</div>)
}
}
//returning objects to the DOM
return (
<div>
{authChecker()}
</div>
)
}