I need your ideasssssssss.
renderIt = () => {
if(!this.state.user){
return <Login />
}else {
return <Home />
}
}
here I check is the user is logged in, if he is not logged in <Login /> is displayed, when he logs itself in, then <Home /> is displayed.
Problem is, when I go log out, and refresh, I see <Home/> page for a fraction of a second even if I am not logged in.
componentDidMount = () => {
this.authListener();
}
authListener = () => {
firebase
.auth()
.onAuthStateChanged((user) => user ? this.setState({user}) : this.setState({user: null}))
}
this.state.user?null, while it checks the user's authentication state. Then, once it has restored the state, it calls you with the user. So you should briefly see the Login screen and then the home screen, not the other way around. If that is really what you see, can you set up a repro on a site like jsbin or stackblitz, so I can have a look?