Skip to content

Instantly share code, notes, and snippets.

@daubattu
Created August 11, 2020 07:57
Show Gist options
  • Save daubattu/bb21912fc17ea45cb4b4349b1d5befb5 to your computer and use it in GitHub Desktop.
Save daubattu/bb21912fc17ea45cb4b4349b1d5befb5 to your computer and use it in GitHub Desktop.
How to push notification in NuxtJS with Firebase Cloud Messaging
<template></template>
<script>
import firebase from '../plugins/firebase';
export defautl {
created() {
const messaging = firebase.messaging();
messaging
.requestPermission()
.then(() => {
console.log('Notification permission granted.');
return messaging.getToken();
})
.then((token) => {
// You update this token for server by call api
console.log('The token is: ', token);
})
.catch(function (err) {
console.log('Unable to get permission to notify.', err);
});
messaging.onMessage(function (payload) {
console.log('Message received. ', payload);
});
}
}
</script>
@kossa
Copy link

kossa commented Feb 10, 2023

Can you share plugins/firebase.js ?

@kossa
Copy link

kossa commented Feb 10, 2023

Ohh I found it, thank you anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment