fetch request on internal action
I am trying to send an email using nodemailer and gmail. I created an api in next js api app router.
export const newUserEmail = internalAction({
args: { email: v.string(), name: v.string() },
handler: async (ctx, args) => {
const newUser = await fetch('http://localhost:3000/api/email/newUser', {
method: 'POST',
body: JSON.stringify({ email: args.email, name: args.name }),
});
console.log('convex email', newUser);
return newUser;
},
});
I am getting this error from convex log:
Uncaught Error: Request to http://localhost:3000/api/email/deleteUser forbidden.
Please how can I resolve this.
6 Replies
Your convex functions run in the cloud, they don't have access to your localhost.
Have you tried using nodemailer directly via "use node" Convex action?
ngrok & tunnelmole are proxies to expose localhost to a url to hit from the cloud while testing. but agree that you shouldn't need api endpoints outside of Convex - no need to go to a different server to run code if you don't have to.
Yes, but I am getting this error:
This is my code:
Missing credentials for "PLAIN"Do you have all relevant environment variables set on your Convex dashboard? https://docs.convex.dev/production/environment-variables
Environment Variables | Convex Developer Hub
Store and access environment variables in Convex
Thanks much it works perfectly