Skip to content

Commit

Permalink
Merge pull request #437 from shreyas1434shinde/InAppNotification
Browse files Browse the repository at this point in the history
Notification id's added in ENV
  • Loading branch information
itsvick authored Nov 27, 2024
2 parents 881018d + 9d93b5e commit 9ea52fe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
12 changes: 1 addition & 11 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
11 changes: 6 additions & 5 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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_FCM_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) => {
Expand Down
11 changes: 11 additions & 0 deletions firebaseConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FCM_API_KEY,
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,
};

export default firebaseConfig;
12 changes: 3 additions & 9 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9ea52fe

Please sign in to comment.