我遇到了负责向用户发送电子邮件验证的 Firebase 云功能的问题。该函数似乎执行成功,并且日志表明验证电子邮件已发送。然而,用户报告说他们没有收到电子邮件。
Firebase 云功能代码:
exports.sendEmailVerification = functions.https.onCall(
async (data, context) => {
try {
const user = context.auth;
if (!user) {
throw new functions.https.HttpsError(
"invalid-argument", "User not authenticated");
}
const uid = user.uid;
// Trigger the email verification process
await admin.auth().updateUser(uid, {
emailVerified: false,
});
console.log("Verification email sent to:", uid);
return {success: true};
} catch (error) {
console.error("Error sending verification email:", error);
throw new functions.https.HttpsError(
"internal", "Error sending verification email");
}
});
采取的故障排除步骤:
附加信息:
为了解决此问题,我是否可能缺少其他步骤或配置设置?任何有关如何进一步诊断和解决此问题的见解或建议将不胜感激。
找到解决方案,问题是代码依赖于admin SDK中不存在的云函数(sendEmailVerification)。我删除了 Cloud Function,并直接使用 Firebase 身份验证和 SDK 处理电子邮件验证。