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.