Firebase Messaging WIP to clean up service worker and implement proper notifications.
Missed in last commit
This commit is contained in:
@@ -24,8 +24,6 @@ export const getCurrentUser = () => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const updateCurrentUser = (userDetails) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const unsubscribe = auth.onAuthStateChanged((userAuth) => {
|
||||
@@ -42,9 +40,9 @@ try {
|
||||
messaging = firebase.messaging();
|
||||
// Project Settings => Cloud Messaging => Web Push certificates
|
||||
messaging.usePublicVapidKey(process.env.REACT_APP_FIREBASE_PUBLIC_VAPID_KEY);
|
||||
console.log("Firebase Messaging initialized successfully.");
|
||||
console.log("**********[FCM UTIL] FCM initialized successfully.");
|
||||
} catch {
|
||||
console.log("Firebase Messaging is likely unsupported.");
|
||||
console.log("**********[FCM UTIL] Firebase Messaging is likely unsupported.");
|
||||
}
|
||||
|
||||
export { messaging };
|
||||
@@ -62,3 +60,33 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||
};
|
||||
analytics.logEvent(eventName, eventParams);
|
||||
};
|
||||
|
||||
messaging.onMessage((payload) => {
|
||||
console.log("**********UTILS Message received. ", payload);
|
||||
// [START_EXCLUDE]
|
||||
// Update the UI to include the received message.
|
||||
//appendMessage(payload);
|
||||
|
||||
// [END_EXCLUDE]
|
||||
});
|
||||
|
||||
messaging.onTokenRefresh(() => {
|
||||
messaging
|
||||
.getToken()
|
||||
.then((refreshedToken) => {
|
||||
console.log("**********Token refreshed.");
|
||||
// Indicate that the new Instance ID token has not yet been sent to the
|
||||
// app server.
|
||||
// setTokenSentToServer(false);
|
||||
// // Send Instance ID token to app server.
|
||||
// sendTokenToServer(refreshedToken);
|
||||
// // [START_EXCLUDE]
|
||||
// // Display new Instance ID token and clear UI of all previous messages.
|
||||
// resetUI();
|
||||
// [END_EXCLUDE]
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("**********Unable to retrieve refreshed token ", err);
|
||||
// showToken("Unable to retrieve refreshed token ", err);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user