feat: new secrets

This commit is contained in:
2026-07-20 15:23:16 +02:00
parent 5a6833c1a2
commit 3fff09ba81
18 changed files with 121 additions and 109 deletions
+28 -21
View File
@@ -4,9 +4,16 @@ const { refList, ALERT_TYPE } = require('../index')
const { Expo } = require('expo-server-sdk')
const { Resend } = require('resend')
const { basicTemplate } = require('../helpers/email')
const { RESEND_API_KEY } = require('../config/keys')
const { RESEND_API_KEY } = require('../config/secrets')
const resendInstance = RESEND_API_KEY ? new Resend(RESEND_API_KEY) : null
let resendInstance = null
const getResendInstance = () => {
if (!resendInstance) {
resendInstance = new Resend(RESEND_API_KEY.value())
}
return resendInstance
}
// Initialisation de Expo SDK
let expo = new Expo()
@@ -58,7 +65,11 @@ function buildNotificationEmailPayload({ title = '', message = '', template = {}
}
exports.sendNotificationWhenDocIsCreated = onDocumentCreated(
{ region: 'europe-west1', document: 'notifications/{notificationId}' },
{
region: 'europe-west1',
document: 'notifications/{notificationId}',
secrets: [RESEND_API_KEY],
},
async (event) => {
try {
const {
@@ -112,24 +123,20 @@ exports.sendNotificationWhenDocIsCreated = onDocumentCreated(
}
if ((emailNotifications || mailOnly) && !!receiverEmail) {
if (!resendInstance) {
console.warn('Resend client not configured; unable to send notification email.')
} else {
try {
const { subject, html } = buildNotificationEmailPayload({
title,
message,
template: notifData?.email,
})
await resendInstance.emails.send({
from: EMAIL_FROM,
to: [receiverEmail],
subject,
html,
})
} catch (e) {
console.log('Error sending email:', e)
}
try {
const { subject, html } = buildNotificationEmailPayload({
title,
message,
template: notifData?.email,
})
await getResendInstance().emails.send({
from: EMAIL_FROM,
to: [receiverEmail],
subject,
html,
})
} catch (e) {
console.log('Error sending email:', e)
}
} else {
console.log(