Skip to content

Instantly share code, notes, and snippets.

@Mohammad-Faisal
Last active November 2, 2020 16:23
Show Gist options
  • Save Mohammad-Faisal/6a0364cb950b221fe9985191753d4f81 to your computer and use it in GitHub Desktop.
Save Mohammad-Faisal/6a0364cb950b221fe9985191753d4f81 to your computer and use it in GitHub Desktop.
import firebase from 'firebase'
export const useFirebaseNotificationProvider = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./firebase-messaging-sw.js')
.then(function (registration) {
console.log('Registration successful, scope is:', registration.scope)
})
.catch(function (err) {
console.log('Service worker registration failed, error:', err)
})
}
firebase
.messaging()
.requestPermission()
.then(() => firebase.messaging().getToken())
.then((firebaseToken) => {
console.log(firebaseToken)
})
.catch((err) => {
console.log(err)
})
firebase.messaging().onMessage((payload) => {
console.log('payload is ', payload)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment