O'Reilly logo

Progressive Web Apps with React by Scott Domes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required