I am doing this
const firebaseApp = initializeApp(configs.FIREBASE)
const messaging = getMessaging(firebaseApp)
getToken(messaging, {
vapidKey: configs.FIREBASE.vapidKey
})
.then((currentToken) => {
if (currentToken) {
fcm_token.value = currentToken
} else {
// Show permission request UI
console.log('No registration token available in app. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token in app. ', err)
// ...
});
onMessage(messaging, (payload) => {
const notificationTitle = payload.notification.title
Notify.create(notificationTitle)
const notificationOptions = {
body: payload.notification.body,
icon: payload.notification.icon,
click_action: payload.notification.click_action
}
if (!('Notification' in window)) {
return;
}
if (Notification.permission === 'granted') {
const notification = new Notification(notificationTitle, notificationOptions)
notification.onclick = function (event) {
event.preventDefault()
window.open(payload.notification.click_action, '_blank')
notification.close()
}
}
})
I cannot find info about life of currentToken. How much time does it long?
Also... If/when it expires, how my app can be aware of its die?