October 2017
Intermediate to advanced
302 pages
7h 27m
English
Let's start with covering the latter case, creating a new token. We'll make a new method called registerToken, passing in the result of the getToken call:
saveTokenToServer() { this.messaging.getToken().then(res => { if (this.tokensLoaded) { const existingToken = this.findExistingToken(res); if (existingToken) { // Replace existing token } else { this.registerToken(res); } } }); }
Then, our new method:
registerToken(token) { firebase .database() .ref('fcmTokens/') .push({ token: token, user_id: this.user.uid }); }
We save the token, along with the user ID. Perfect.
Read now
Unlock full access