diff --git a/config.json b/config.json index 527f8c0c..c4d9f79c 100644 --- a/config.json +++ b/config.json @@ -17,15 +17,5 @@ "label": "ଓଡ଼ିଆ", "code": "or" } - ], - "firebaseConfig": { - "apiKey": "AIzaSyCmhNz-HMkkf42QNmnf7pnZm49FP5g4INw", - "authDomain": "backend-e99c8.firebaseapp.com", - "projectId": "backend-e99c8", - "storageBucket": "backend-e99c8.appspot.com", - "messagingSenderId": "839139131975", - "appId": "1:839139131975:web:90af50d01e2eb0f510e762", - "measurementId": "G-5237RSF3TC" - }, - "vapidKey": "BOZ_JkC62vr767LoC7APU26ZdGYW5htBkfqIEtsVX6zmE3Fi-XgcN_TggSaXKh5rGKcaa4vuQxaYiRPU2B955GI" + ] } \ No newline at end of file diff --git a/firebase.js b/firebase.js index 7ee466eb..7f846c16 100644 --- a/firebase.js +++ b/firebase.js @@ -1,8 +1,9 @@ import { initializeApp } from "firebase/app"; import { getMessaging, onMessage, getToken } from "firebase/messaging"; -import config from './config.json'; +// import config from './config.json'; +import firebaseConfig from './firebaseConfig'; -const firebaseApp = initializeApp(config.firebaseConfig); +const firebaseApp = initializeApp(firebaseConfig); let messaging; if (typeof window !== 'undefined') { @@ -15,15 +16,15 @@ export const requestPermission = async () => { if (permission === 'granted') { const token = await getToken(messaging, { - vapidKey: "BOZ_JkC62vr767LoC7APU26ZdGYW5htBkfqIEtsVX6zmE3Fi-XgcN_TggSaXKh5rGKcaa4vuQxaYiRPU2B955GI", + vapidKey: process.env.NEXT_PUBLIC_VAPID_KEY, }); console.log('Notification token:', token); return token; } else { - console.warn("Notification permission denied"); + console.warn("Notification permission denied"); return null; } -}; +}; export const onMessageListener = () => new Promise((resolve) => { diff --git a/firebaseConfig.js b/firebaseConfig.js new file mode 100644 index 00000000..061d8c31 --- /dev/null +++ b/firebaseConfig.js @@ -0,0 +1,11 @@ +const firebaseConfig = { + apiKey: process.env.NEXT_PUBLIC_FCM_API_KEY, + authDomain: process.env.NEXT_PUBLIC_AUTH_DOMAIN, + projectId: process.env.NEXT_PUBLIC_PROJECT_FCM_ID, + storageBucket: process.env.NEXT_PUBLIC_STORAGE_BUCKET, + messagingSenderId: process.env.NEXT_PUBLIC_MESSAGING_SENDER, + appId: process.env.NEXT_PUBLIC_FCM_APP_ID, + measurementId: process.env.NEXT_PUBLIC_FCM_MEASUREMENT_ID, +}; + +export default firebaseConfig; \ No newline at end of file diff --git a/public/firebase-messaging-sw.js b/public/firebase-messaging-sw.js index 88f5a61a..a5daf109 100644 --- a/public/firebase-messaging-sw.js +++ b/public/firebase-messaging-sw.js @@ -1,17 +1,11 @@ // Scripts for firebase and firebase messaging importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js'); +import firebaseConfig from '../firebaseConfig'; -const firebaseConfig = { - apiKey: "AIzaSyCmhNz-HMkkf42QNmnf7pnZm49FP5g4INw", - authDomain: "backend-e99c8.firebaseapp.com", - projectId: "backend-e99c8", - storageBucket: "backend-e99c8.appspot.com", - messagingSenderId: "839139131975", - appId: "1:839139131975:web:90af50d01e2eb0f510e762", - measurementId: "G-5237RSF3TC" -}; + +const firebaseConfig = firebaseConfig // Initialize the Firebase app in the service worker by passing the generated config firebase.initializeApp(firebaseConfig); // Retrieve firebase messaging