async function saveMessagingDeviceToken()

in web/src/index.js [154:178]


 async function saveMessagingDeviceToken() {
   try {
     const currentToken = await getToken(getMessaging());
     if (currentToken) {
       console.log('Got FCM device token:', currentToken);
       // Saving the Device Token to Cloud Firestore.
       const tokenRef = doc(getFirestore(), 'fcmTokens', currentToken);
       await setDoc(tokenRef, { uid: getAuth().currentUser.uid });

       // This will fire when a message is received while the app is in the foreground.
       // When the app is in the background, firebase-messaging-sw.js will receive the message instead.
       onMessage(getMessaging(), (message) => {
         console.log(
           'New foreground notification from Firebase Messaging!',
           message.notification
         );
       });
     } else {
       // Need to request permissions to show notifications.
       requestNotificationsPermissions();
     }
   } catch(error) {
     console.error('Unable to get messaging token.', error);
   };
 }