enh
This commit is contained in:
parent
37f5d48bbb
commit
ffa4a0ed44
2 changed files with 19 additions and 19 deletions
|
|
@ -1,14 +1,14 @@
|
|||
import admin from 'firebase-admin';
|
||||
import path from 'path';
|
||||
|
||||
// Initialize Firebase Admin SDK
|
||||
const serviceAccountPath = path.join('.', 'creds', 'fcm-v1-account.json');
|
||||
// // Initialize Firebase Admin SDK
|
||||
// const serviceAccountPath = path.join('.', 'creds', 'fcm-v1-account.json');
|
||||
|
||||
if (!admin.apps.length) {
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccountPath),
|
||||
});
|
||||
}
|
||||
// if (!admin.apps.length) {
|
||||
// admin.initializeApp({
|
||||
// credential: admin.credential.cert(serviceAccountPath),
|
||||
// });
|
||||
// }
|
||||
|
||||
export const messaging = admin.messaging();
|
||||
export default admin;
|
||||
// export const messaging = admin.messaging();
|
||||
// export default admin;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { users, complaints, orders, orderItems, notifCreds, userNotifications, u
|
|||
import { eq, sql, desc, asc, count, max } from 'drizzle-orm';
|
||||
import { ApiError } from '../../lib/api-error';
|
||||
import { Expo } from 'expo-server-sdk';
|
||||
import { messaging } from '../../lib/firebase';
|
||||
// import { messaging } from '../../lib/firebase';
|
||||
import { generateSignedUrlFromS3Url } from '../../lib/s3-client';
|
||||
|
||||
// Toggle between notification providers: 'expo' | 'fcm'
|
||||
|
|
@ -434,16 +434,16 @@ export const userRouter = {
|
|||
|
||||
// Send notifications using Firebase Admin SDK
|
||||
try {
|
||||
const response = await messaging.sendEach(messages);
|
||||
sentCount = response.successCount;
|
||||
failedCount = response.failureCount;
|
||||
// const response = await messaging.sendEach(messages);
|
||||
// sentCount = response.successCount;
|
||||
// failedCount = response.failureCount;
|
||||
|
||||
// Log failed tokens
|
||||
response.responses.forEach((resp, idx) => {
|
||||
if (!resp.success) {
|
||||
console.error(`Failed to send to token ${tokens[idx].token}:`, resp.error);
|
||||
}
|
||||
});
|
||||
// // Log failed tokens
|
||||
// response.responses.forEach((resp, idx) => {
|
||||
// if (!resp.success) {
|
||||
// console.error(`Failed to send to token ${tokens[idx].token}:`, resp.error);
|
||||
// }
|
||||
// });
|
||||
} catch (error) {
|
||||
console.error('Error sending push notifications:', error);
|
||||
throw new ApiError('Failed to send push notifications', 500);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue