Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
Invalid Grant nodemon in NextJS and Typescript

I am receiving an invalid grand error from nodeMailer in NextJS, also Typescript is underlining one of the lines, the strange thing is that it worked on one of my other projects

this is the code

const sendEmailToGuestsHandler: NextApiHandler = async (req, res) => {
  const REDIRECT_URI = "https://developers.google.com/oauthplayground/";
  const { CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN } = process.env;

  if (!CLIENT_ID || !CLIENT_SECRET || !REFRESH_TOKEN) {
    return res.status(404).json({ error: "Invalid secrets" });
  }
  const oauth2Client = new google.auth.OAuth2(
    CLIENT_ID,
    CLIENT_SECRET,
    REDIRECT_URI
  );
  oauth2Client.setCredentials({ refresh_token: REFRESH_TOKEN });
  const accessToken = await oauth2Client.getAccessToken();

  const emailTransport = createTransport({
    service: "gmail",
    auth: {
      type: "OAuth2",
      user: "xf@xfaang.com",
      clientId: CLIENT_ID,
      clientSecret: CLIENT_SECRET,
      refreshToken: REFRESH_TOKEN,
      accessToken: accessToken,
    },
  });

  const mailOptions = {
    from: '"John" <xfre@example.com>',
    to: "john@gmail.com",
    subject: `estimation report`,
    attachments: [
      {
        filename: `_estimation_report.pdf`,
        contentType: "application/pdf",
        content: "<div>elo</div>",
        encoding: "base64",
      },
    ],
    text: "<div>elo</div>",
    html: "<div>elo</div>",
  };

  await emailTransport.sendMail(mailOptions);

red underline is under

service: "gmail",

And I am not sure if this is the reason why I'm getting

error - Error: invalid_grant

in the d.ts file there is a lot of overloads of this function, previously I did not use TS and followed this tutorial https://www.youtube.com/watch?v=-rcRf7yswfM&list=LL&index=9 seems more legit than auth via login and password.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda