I'm trying to build an web app using react and I kind of hit the wall.
The thing is, I don't want any users who has already logged in to access the login page.
I tried to redirect them using render method and componentDidMount method, but since the render method is called before componentDidMount, the login page flashes out before redirection.
These are my codes.
I'm using redux and firebase to control the component state and authenticate.
class CenterPanel extends Component {
render() {
const { user }=this.props;
if(user!=null) { //this is how I tried to redirect
return ( //
<Redirect to='/somewhereNotHere' />
);
}
return ( //this flashes out before redirection
<div className={cx('center_panel')}>
<div className={cx('button')}>
login
</div>
</div>
);
}
componentDidMount() {
const { changeUserStatus }=this.props;
firebase.auth().onAuthStateChanged(
(user) => changeUserStatus(user)
);
}
}
would appreciate any kind of advice. Thx in advance.