From 6158f15e9d15521f99619fa0a6e81cfc84d1a8b1 Mon Sep 17 00:00:00 2001 From: ttpl-rt-217 Date: Wed, 27 Nov 2024 12:36:05 +0530 Subject: [PATCH 1/2] NOfication id's added in env --- config.json | 12 +----------- firebase.js | 11 ++++++----- firebaseConfig.js | 11 +++++++++++ public/firebase-messaging-sw.js | 12 +++--------- 4 files changed, 21 insertions(+), 25 deletions(-) create mode 100644 firebaseConfig.js 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 From 9d93b5e6097504b7806d43bdb3ae0aed2307084c Mon Sep 17 00:00:00 2001 From: ttpl-rt-217 Date: Wed, 27 Nov 2024 14:17:03 +0530 Subject: [PATCH 2/2] env upadated for FCM --- firebase.js | 2 +- firebaseConfig.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firebase.js b/firebase.js index 7f846c16..4ba9c436 100644 --- a/firebase.js +++ b/firebase.js @@ -16,7 +16,7 @@ export const requestPermission = async () => { if (permission === 'granted') { const token = await getToken(messaging, { - vapidKey: process.env.NEXT_PUBLIC_VAPID_KEY, + vapidKey: process.env.NEXT_PUBLIC_FCM_VAPID_KEY, }); console.log('Notification token:', token); return token; diff --git a/firebaseConfig.js b/firebaseConfig.js index 061d8c31..a578ec27 100644 --- a/firebaseConfig.js +++ b/firebaseConfig.js @@ -1,10 +1,10 @@ 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, + authDomain: process.env.NEXT_PUBLIC_FCM_AUTH_DOMAIN, + projectId: process.env.NEXT_PUBLIC_FCM_PROJECT_FCM_ID, + storageBucket: process.env.NEXT_PUBLIC_FCM_STORAGE_BUCKET, + messagingSenderId: process.env.NEXT_PUBLIC_FCM_MESSAGING_SENDER, + appId: process.env.NEXT_PUBLIC_FCM_FCM_APP_ID, measurementId: process.env.NEXT_PUBLIC_FCM_MEASUREMENT_ID, };