October 2017
Intermediate to advanced
302 pages
7h 27m
English
We already have a method to handle user changes inside App.js--our old friend, onAuthStateChanged. Let's hook in to that, and use that to call a method inside NotificationResource:
componentDidMount() { this.notifications = new NotificationResource(firebase.messaging(), firebase.database()); firebase.auth().onAuthStateChanged((user) => { if (user) { this.setState({ user }); this.listenForMessages(); this.notifications.changeUser(user); } else { this.props.history.push('/login') } });
Then, inside NotificationResource:
changeUser(user) { this.user = user; }
Incidentally, this helps us solve another problem with tokens. As noted earlier, onTokenRefresh is called when a new token is generated, either ...
Read now
Unlock full access