1

I am registering new users in client side and then I read somewhere and also other community members told me that having this function in Cloud will trigger it automatically and send an email after each user has been created:

exports.sendWelcomeEmail = functions.region('europe-west6').auth.user().onCreate((user) => {
    user.sendEmailVerification().then(function () {
// Email sent.
    }).catch(function (error) {
// An error happened.
    });
});

The problem is that (according to the documentation) sendEmailVerification() does not work in Admin SDK, only in Client SDK. Am I missing something here?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
showtime
  • 1
  • 1
  • 17
  • 48
  • 1
    Methods to send email or text messages to an individual user are only available in the client-side SDKs, and can only be used to send message to the currently signed in user. – Frank van Puffelen Jul 26 '20 at 03:51

1 Answers1

2

The functions.auth.user().onCreate(user) function has a user parameter user which is a UserRecord type. It doesn't have sendEmailVerification.

See https://firebase.google.com/docs/reference/functions/providers_auth_#userrecord

sendEmailVerification, as per the docs exists in the Client SDK, via https://firebase.google.com/docs/reference/js/firebase.User.

As of 2020, there's an existing github issue that hasn't been resolved: https://github.com/firebase/firebase-admin-node/issues/46 which has some workarounds (which involves calling the REST API, or installing the Firebase Client SDK on the server)

However, if you have a SMTP server and prefer to send email via that, see https://firebase.google.com/docs/auth/admin/email-action-links.

References

hrgui
  • 590
  • 2
  • 5