2

I implemented sending emails via nodemailer.

Now when I create new user, that new user get "welcome email".

Problem is cus that "welcome email" should contain option for resetting password.

How to add Firebase Resetting link in nodemailer email template?

  • This is my Email Template code for nodemailer

    const output = `
     <p>You have access to the Church Mutual Assignment Tool.</p>
     <p>Follow this link to create new password for your account ${userRecord.email}:</p>
       <a href="${resetPasswordLink}">
         ${resetPasswordLink}
       </a>
       <p>Thanks,</p>
       <p>Your Church Mutual Assignment Tool team</p>
     `
     let message = {
       from: 'nyik6nntutmq3vz6@ethereal.email',
       to: `${user.email}`,
       subject: 'Welcome to the Church Mutual Assignment Tool',
       text: 'Plaintext version of the message',
       html: output
     }
    
  • This is my Nodemailer code:

      var mailer = require('nodemailer')
      var mailConfig = {
      host: 'smtp.ethereal.email',
      port: 587,
      auth: {
        user: 'nyik6nntutmq3vz6@ethereal.email',
        pass: '3cbRjkZdPquDqA725s'
      }
    }
    
    var transporter = mailer.createTransport(mailConfig)
    
    module.exports = transporter
    
James Delaney
  • 1,765
  • 1
  • 17
  • 36

1 Answers1

2

The Admin SDK now has some methods that allow you to do just this exact thing. Check out the docs on the email action links, specifically the "Generate password reset email link" section.

// Admin SDK API to generate the password reset link.
const email = 'user@example.com';
admin.auth().generatePasswordResetLink(email, actionCodeSettings)
    .then((link) => {
        // Do stuff with link here
    })
    .catch((error) => {
        // Some error occurred.
    });

Full disclosure - I haven't actually used any of those functions, and I'm a little concerned that the page in question refers a lot to mobile apps - so you might have to pass it the mobile app config.

const actionCodeSettings = {
    // URL you want to redirect back to. The domain (www.example.com) for
    // this URL must be whitelisted in the Firebase Console.
    url: 'https://www.example.com/checkout?cartId=1234',
    // This must be true for email link sign-in.
    handleCodeInApp: true,
    iOS: {
        bundleId: 'com.example.ios'
    },
    android: {
        packageName: 'com.example.android',
        installApp: true,
        minimumVersion: '12'
    },
    // FDL custom domain.
    dynamicLinkDomain: 'coolapp.page.link'
};

On the other hand, the page also says these features provide the ability to:

Ability to customize how the link is to be opened, through a mobile app or a browser, and how to pass additional state information, etc.

Which sounds promising, allowing it to open in the browser... but if you are developing for web - and the function errors out when not provided iOS/Android information... then I'm afraid you'll have to do it the old fashioned approach and create your own implementation... but I'm leaning towards this .generatePasswordResetLink should work for you.

JeremyW
  • 5,157
  • 6
  • 29
  • 30