I am using Firebase in my React project. The issue that the app would not redirect to Login page when users not logged in yet.
In my Home.js I have
This page allows to only users who have already logged in the app.
class Home extends React.Component {
constructor(props) {
super(props);
}
logout = () => {
firebase.auth().signOut();
this.props.history.push("/login");
};
render() {
if (firebase.auth().currentUser === null) {
return <Redirect to="/login" />;
}
return (
<div>
<div>
<Button variant="contained" color="primary" onClick={this.logout}>
Google Logoout
</Button>
</div>
</div>
);
}
}
export default withRouter(Home);
Actually, I use for classifying if the user is logged in or not by firebase.auth().currentUser.