node.jsfirebase-authenticationgoogle-cloud-functionsfirebase-adminemail-verification

Verification emails sent from Firebase Cloud Function not received by the user


I'm facing an issue with the Firebase Cloud Function responsible for sending email verification to users. The function appears to execute successfully, and the logs indicate that the verification email is sent. However, users report that they are not receiving the emails.

enter image description here

Firebase Cloud Function Code:

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");
      }
    });

Troubleshooting Steps Taken:

Additional Information:

Are there additional steps or configuration settings that I might be missing to troubleshoot this issue? Any insights or suggestions on how to further diagnose and resolve this problem would be greatly appreciated.


Solution

  • Found a solution, the problem was that the code was relying on a Cloud Function (sendEmailVerification) that didn't exist in the admin SDK. I removed the Cloud Function and handled email verification directly using the Firebase Authentication and SDK.