Tracking tokens

A token is a unique identifier for your user's device. It helps Firebase figure out where to send push notifications. In order for our notifications to be sent properly, we need to keep a record of all current device tokens in our database, and ensure that it's up to date.

We can access the token of our user's device via the Firebase messaging library. Two methods in particular will be useful: onTokenRefresh and getToken. Both have fairly self-explanatory names, so we’ll dive right into the implementation:

 export default class NotificationResource {     constructor(messaging) {       this.messaging = messaging;      try {        this.messaging          .requestPermission()          .then(res => {            console.log('Permission granted');          })         .catch(err => { console.log('no ...

Get Progressive Web Apps with React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.