April 2018
Intermediate to advanced
284 pages
6h 43m
English
As of right now, every time we refresh the page, our application forgets that the user was already logged in. However, Firebase has an event listener—onAuthStateChange()—that can actually check every single time the application loads to see whether the authentication state is changed or not, whether the user was already signed in the last time they visited the app. If it's true, then you can automatically sign them back in.
We'll write this method inside our componentDidMount() in app.js. Just look at the following code:
componentWillMount() { this.removeAuthListener = firebase.auth().onAuthStateChanged((user) =>{ if(user){ console.log("App user data",user); this.setState({ authenticated:true, data:user.providerData ...