I'm following an authentication tutorial, and I'm trying to understand this:
componentDidMount() {
this.props.firebase.auth.onAuthStateChanged(authUser => {
authUser
? this.setState({ authUser })
: this.setState({ authUser: null });
});
}
If componentDidMount()
is called after Component rendering, why a function that evaluates if the user is logged in should be called after the renderization?
I think that the result of this is:
- React renders the unathenticated page
- After that, it evaluates if the user is authenticated
- Finally renders the authenticated page
Instead of:
- Evaluate if the user is authenticated
- Render the authenticated page
Can you say me in what part of the cycle I'm wrong?
I understand that componentDidMount()
is used for don't block the flow of the page rendering, but if a user have a session previously, and enters again to the website, he can't access to the private page until the public page is rendered and the onAuthStateChanged()
is called.