This commit is contained in:
shafi54 2026-02-08 21:52:26 +05:30
parent 37f5d48bbb
commit ffa4a0ed44
2 changed files with 19 additions and 19 deletions

View file

@ -1,14 +1,14 @@
import admin from 'firebase-admin'; import admin from 'firebase-admin';
import path from 'path'; import path from 'path';
// Initialize Firebase Admin SDK // // Initialize Firebase Admin SDK
const serviceAccountPath = path.join('.', 'creds', 'fcm-v1-account.json'); // const serviceAccountPath = path.join('.', 'creds', 'fcm-v1-account.json');
if (!admin.apps.length) { // if (!admin.apps.length) {
admin.initializeApp({ // admin.initializeApp({
credential: admin.credential.cert(serviceAccountPath), // credential: admin.credential.cert(serviceAccountPath),
}); // });
} // }
export const messaging = admin.messaging(); // export const messaging = admin.messaging();
export default admin; // export default admin;

View file

@ -5,7 +5,7 @@ import { users, complaints, orders, orderItems, notifCreds, userNotifications, u
import { eq, sql, desc, asc, count, max } from 'drizzle-orm'; import { eq, sql, desc, asc, count, max } from 'drizzle-orm';
import { ApiError } from '../../lib/api-error'; import { ApiError } from '../../lib/api-error';
import { Expo } from 'expo-server-sdk'; import { Expo } from 'expo-server-sdk';
import { messaging } from '../../lib/firebase'; // import { messaging } from '../../lib/firebase';
import { generateSignedUrlFromS3Url } from '../../lib/s3-client'; import { generateSignedUrlFromS3Url } from '../../lib/s3-client';
// Toggle between notification providers: 'expo' | 'fcm' // Toggle between notification providers: 'expo' | 'fcm'
@ -434,16 +434,16 @@ export const userRouter = {
// Send notifications using Firebase Admin SDK // Send notifications using Firebase Admin SDK
try { try {
const response = await messaging.sendEach(messages); // const response = await messaging.sendEach(messages);
sentCount = response.successCount; // sentCount = response.successCount;
failedCount = response.failureCount; // failedCount = response.failureCount;
// Log failed tokens // // Log failed tokens
response.responses.forEach((resp, idx) => { // response.responses.forEach((resp, idx) => {
if (!resp.success) { // if (!resp.success) {
console.error(`Failed to send to token ${tokens[idx].token}:`, resp.error); // console.error(`Failed to send to token ${tokens[idx].token}:`, resp.error);
} // }
}); // });
} catch (error) { } catch (error) {
console.error('Error sending push notifications:', error); console.error('Error sending push notifications:', error);
throw new ApiError('Failed to send push notifications', 500); throw new ApiError('Failed to send push notifications', 500);