Я использую облачные функции Firebase.
Код: Выделить всё
exports.sendInvitationEmail = functions.https.onCall(async (data, context) => {
console.log("📥 Получени сурови данни:", data);
exports.sendInvitationEmail = functions.https.onCall((data, context) => {
const payload = unwrapPayload(data);
console.log("📦 Payload след unwrap:", payload);
const { email, code, companyName, role } = payload;
if (!email) {
throw new functions.https.HttpsError('invalid-argument', 'Невалиден или празен имейл');
}
});
const payload = data;
console.log("📦 Payload after unwrap:", payload);
const { email, code, companyName, role } = payload;
console.log("📧 Email:", email);
console.log("🔐 Code:", code);
console.log("🏢 Company:", companyName);
console.log("🎭 Role:", role);
// Valid e-mail check
if (!email || typeof email !== 'string' || !email.includes('@')) {
console.error("❌ Invalid/empty:", email);
throw new functions.https.HttpsError('invalid-argument', 'Invalid e-mail');
}
const mailOptions = {
from: '"here's my app name" ',
to: email,
subject: `.........(here's my email text`,
};
try {
console.log('📤 Sent e-mail to:', email);
await transporter.sendMail(mailOptions);
console.log("✅ Email изпратен успешно.");
return { success: true };
} catch (error) {
console.error("❗ Грешка при изпращане на email:", error);
throw new functions.https.HttpsError("unknown", "Неуспешно изпращане на email");
}
});
< /code>
Вот где я называю функцию: < /p>
final callable = FirebaseFunctions.instance.httpsCallable('sendInvitationEmail');
await callable.call({
'email': email,
'code': invitationCode,
'companyName': companyName,
'role': role,
});
< /Code>
Сообщение об ошибке терминала трепета HidingThisbutaccrate, роль: сотрудник}
i /wrlutter (15083): Отправление в: отправленный код: C84ba520-0f82-4215-892f-25338584a8bb, компания: hidden
i /fluth [Firebase_functions/Invalid-Argument] Недопустимая электронная почта
Журналы Firebase:
data: {
code: 'b7825155-8841-40d4-9dd7-259691419351',
role: 'employee',
companyName: 'hidden',
email: 'shalqlq@mail.bg'
},
acceptsStreaming: false
}
2025-07-06T19:03:32.462103Z ? sendinvitationemail: Invalid-email: undefined
Подробнее здесь: https://stackoverflow.com/questions/796 ... -undefined