Skip to content

Instantly share code, notes, and snippets.

@birchb
Created June 23, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save birchb/203df49fed169cc443a1708928bc3495 to your computer and use it in GitHub Desktop.
Save birchb/203df49fed169cc443a1708928bc3495 to your computer and use it in GitHub Desktop.
const messaging = firebase.messaging();
messaging.usePublicVapidKey(YOUR_PUBLIC_VAPID_KEY_HERE);
messaging.onTokenRefresh(() => {
messaging.getToken().then(async token => {
const subscribeNotifications = firebase.functions().httpsCallable('subscribeNotifications');
await subscribeNotifications({ token });
});
});
messaging.onMessage(payload => {
console.log('Message received.', payload);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment