Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!