Add enhanced search/filtering and push notifications for prayer reminders

This commit is contained in:
nmemmert committed 2025-11-03 08:04:19 -05:00
1 parent aa3f42479f
commit 1a160135d7
5 files changed
+294 -38

No files matched your search

+38
View File
@@ -4,6 +4,7 @@ import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from 'firebase/storage';
import { getAnalytics } from 'firebase/analytics';
import { getMessaging, onMessage, getToken } from 'firebase/messaging';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
@@ -30,6 +31,16 @@ export const db = getFirestore(app);
// Initialize Firebase Storage and get a reference to the service
export const storage = getStorage(app);
// Initialize Firebase Cloud Messaging
export let messaging: any = null;
if (typeof window !== 'undefined') {
try {
messaging = getMessaging(app);
} catch (error) {
console.warn('FCM not supported in this environment:', error);
}
}
// Initialize Firebase Analytics and get a reference to the service
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let analytics: any = null;
@@ -45,4 +56,31 @@ if (typeof window !== 'undefined') {
export { analytics };
// FCM utility functions
export const requestNotificationPermission = async () => {
if (!messaging) return null;
try {
const permission = await Notification.requestPermission();
if (permission === 'granted') {
const token = await getToken(messaging, {
vapidKey: process.env.NEXT_PUBLIC_FCM_VAPID_KEY || 'your-vapid-key-here'
});
return token;
}
} catch (error) {
console.error('Error requesting notification permission:', error);
}
return null;
};
export const onMessageListener = () =>
new Promise((resolve) => {
if (messaging) {
onMessage(messaging, (payload) => {
resolve(payload);
});
}
});
export { app };