Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda