Search code examples
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:

  • Checked the recipient's email address for correctness.
  • Verified that the recipient's email address is valid and capable of receiving emails.
  • Checked Firebase project configuration for email verification settings.
  • Checked Firebase project quotas to ensure they are not exceeded.
  • Reviewed Cloud Function logs for any errors or warnings related to email sending.

Additional Information:

  • The Cloud Function logs do not show any errors related to email sending.
  • The issue occurs consistently for different users and email addresses.

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.