-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.js
46 lines (41 loc) · 1.48 KB
/
firebase.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { initializeApp } from 'firebase/app';
import { getMessaging, getToken, onMessage } from 'firebase/messaging';
const firebaseConfig = {
apiKey: 'AIzaSyDLeHnHS0p0SHhp9XblU0VUTMGDHTMpmFE',
authDomain: 'push-nofitication-test-f51f4.firebaseapp.com',
projectId: 'push-nofitication-test-f51f4',
storageBucket: 'push-nofitication-test-f51f4.appspot.com',
messagingSenderId: '128761461591',
appId: '1:128761461591:web:311797fe5c0c9f7a749c12',
measurementId: 'G-R80VJLVP9X',
};
initializeApp(firebaseConfig);
const messaging = getMessaging();
export const requestForToken = async () => {
return getToken(messaging, {
vapidKey:
'BHfmxZCCwrB_aPQaSPqGtxm10G6C949A1ybeWYD7-lx3PZTwySekvacseuIHcKRzwQkog44ETUse0ui2EXw7cgk',
})
.then((currentToken) => {
if (currentToken) {
console.log('current token for client: ', currentToken);
return currentToken;
} else {
console.log(
'No registration token available. Request permission to generate one.'
);
}
})
.catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
};
export const onMessageListener = () => {
console.log('onMessageListener');
return new Promise((resolve) => {
onMessage(messaging, (payload) => {
console.log('payload', payload);
resolve(payload);
});
});
};