Home > other >  NodeJS firebase-admin cannot send email verification link
NodeJS firebase-admin cannot send email verification link

Time:11-02

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.

CodePudding user response:

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.

  • Related