-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase.ts
More file actions
70 lines (59 loc) · 2.26 KB
/
firebase.ts
File metadata and controls
70 lines (59 loc) · 2.26 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Import the functions you need from the SDKs you need
import { FirebaseOptions, getApp, initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
import { getStorage, ref } from "firebase/storage";
import { getMessaging, getToken, onMessage } from "firebase/messaging";
import localforage from "localforage";
import { GoogleAuthProvider, getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig: FirebaseOptions = {
apiKey: ",
authDomain: "afyamed-tele.firebaseapp.com",
projectId: "afyamed-tele",
storageBucket: "afyamed-tele.appspot.com",
messagingSenderId: "",
appId: "",
measurementId: "",
};
// Initialize Firebase
export const app = initializeApp(firebaseConfig);
// const analytics = getAnalytics(app);
export const auth = getAuth(app);
export const db = getFirestore(app);
export const googleProvider = new GoogleAuthProvider();
export const storage = getStorage(app);
export const firebaseMessaging = () => getMessaging(app);
export const firebaseCloudMessaging = {
init: async () => {
if (getApp()) {
// Initialize the Firebase app with the credentials
try {
// const messaging = firebase.messaging();
const tokenInLocalForage = await localforage.getItem("fcm_token");
// Return the token if it is alredy in our local storage
if (tokenInLocalForage !== null) {
return tokenInLocalForage;
}
// Request the push notification permission from browser
const status = await Notification.requestPermission();
if (status && status === "granted") {
// Get new token from Firebase
// const fcm_token = await messaging.getToken({
// vapidKey: "your_web_push_certificate_key_pair",
// });
// Set token in our local storage
// if (fcm_token) {
// localforage.setItem("fcm_token", fcm_token);
// return fcm_token;
// }
}
} catch (error) {
console.error(error);
return null;
}
}
},
};