0

I have a Nextjs application running on Firebase as a Cloud Function. I have this nodemailer function that works with a gmail App Password. The problem is that it is inside the code and I have to implement it as a secret.

let nodemailer = require('nodemailer');
  var smtpTransport = require('nodemailer-smtp-transport');

  const transporter = nodemailer.createTransport(
    smtpTransport({
      service: 'gmail',
      auth: {
        user: 'camilo@camiloengineer.com',
        pass: 'MYPASSWORD'
      },
    })
  );

I was able to send the key to the secrets manager, but I have no idea how to get this into code

The Password in GCP secrets

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84

1 Answers1

0

You can use defineSecret() function as mentioned in the documentation. Try:

let nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

const secretName = defineSecret('SECRET_NAME');

const transporter = nodemailer.createTransport(
  smtpTransport({
    service: 'gmail',
    auth: {
      user: 'camilo@camiloengineer.com',
      pass: secretName.value()
    },
  })
);
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • That documentation indicates that defining a secret like that needs to be bound to the Firebase function that's using it. So this seems to only be half the configuration needed to get a working implementation. – MidnightLightning Mar 13 '23 at 12:59