-
Notifications
You must be signed in to change notification settings - Fork 242
/
messaging_get_token.js
26 lines (24 loc) · 937 Bytes
/
messaging_get_token.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This snippet file was generated by processing the source file:
// ./messaging-next/index.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.
// [START messaging_get_token_modular]
import { getMessaging, getToken } from "firebase/messaging";
// Get registration token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache.
const messaging = getMessaging();
getToken(messaging, { vapidKey: '<YOUR_PUBLIC_VAPID_KEY_HERE>' }).then((currentToken) => {
if (currentToken) {
// Send the token to your server and update the UI if necessary
// ...
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
// [END messaging_get_token_modular]