0

I'm using node firebase-admin to manage user as follow.

function (req, res, next) {
  const { email, password } = req.body;
  const auth = getAuth();
  const userRecord = await auth.createUser({ email, password });
  auth.generateEmailVerificationLink(email).then(console.log);
  // this log verify link successfully xyz.firebaseapp.com/__/auth/action?mode=verifyEmail&oobCode=...
  await accountService.createAccount({ id: userRecord.uid, email })
  res.status(200).json(userRecord);
}

I also tried different email and also debug auth.generateEmailVerificationLink function and saw it invoked to firebase auth api and succeed. But cannot find email in mail box or spam.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

1

The generateEmailVerificationLink method of the Firebase Admin SDK only generates the link you would put into a message. Once the link is generated, you then need to embed that link into a message and then send the email using whatever service you desire.

If you want to use the built-in email verification methods, you must use the appropriate sendVerificationEmail method of the client-side SDKs.

The Firebase Client SDKs provide the ability to send users emails containing links they can use for password resets, email address verification, and email-based sign-in. These template-based emails are sent by Google and have limited customizability.

samthecodingman
  • 23,122
  • 4
  • 30
  • 54
  • Thanks @samthecodingman. This answers why I can not receive email. But it create an other problem. The `sendVerificationEmail` requires `currentUser` but in my case I don't use client SDK `createUserWithEmailAndPassword` so I can't use `sendVerificationEmail` directly after request success. – Sy Tran Dung Nov 02 '22 at 07:44
  • Is there any way to reuse response from firebase-admin to log in as current user? ``` const userRecord = await auth.createUser({ email, password }); ``` – Sy Tran Dung Nov 02 '22 at 07:52
  • @SyTranDung The admin SDKs don't have an equivalent of `sendVerificationEmail` because the API it uses relies on anti-spam methods based on things like an IP address. You are expected to send email from your code using tools like Mailgun, NodeMailer, SendGrid, etc. – samthecodingman Nov 03 '22 at 03:07