next email library

Hello im working on password recovery by email feature in next js. which mailing lib/service u suggest
23 Replies
bakdaddy
bakdaddy15mo ago
nodemailer, it's fairly simple you could even use React Email with it Theo made a video about React Email recently https://www.youtube.com/watch?v=Xa1WaSPu5K8&t=166s https://react.email/docs/integrations/nodemailer they give more integrations on their website, you can use the one you'd like https://react.email/docs/integrations/overview
Lumberjack
Lumberjack15mo ago
thanks i'll use react email with nodemailer integration or should i use resend instead ?
bakdaddy
bakdaddy15mo ago
I used nodemailer in my project, works absolute fine for the pass reset purposes, but you could try both and use the one you are more comfortable with
dan
dan15mo ago
Resend
Build, test, and send transactional emails at scale.
Lumberjack
Lumberjack15mo ago
thanks guys if u dont mind i want to send that verification token through that email how can i generate it and make it match both on server and client sides ?
bakdaddy
bakdaddy15mo ago
I used jwt to encode user's id with custom secret phrase that I match on the server jwt js lib has encode and decode methods for it, very handy you can also set expiration date in it for auto rejection if too much time passed const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET!, { expiresIn: "15m", });
dan
dan15mo ago
jwt works for that. either jwt or storing a secret token in the database.
bakdaddy
bakdaddy15mo ago
and you can send the token as a query parameter on the link, like https://your-app.com/forgotPass?token={YOUR_TOKEN_HERE} then you send the token form the query as part of user's request for the password change, and validate it on the server
Lumberjack
Lumberjack15mo ago
what about the process.env.JWT_SECRET! should imake it with openssl?
bakdaddy
bakdaddy15mo ago
yeah, that's what I did
Lumberjack
Lumberjack15mo ago
thanks budd what is the lib for jwt ?
bakdaddy
bakdaddy15mo ago
'openssl rand -base64 32' - it's the terminal command for a secret jsonwebtoken https://www.npmjs.com/package/jsonwebtoken
Lumberjack
Lumberjack15mo ago
damn u're a life saver thanks mate
bakdaddy
bakdaddy15mo ago
https://jwt.io/libraries - you can choose another there's one called Jose but i haven't used it
dan
dan15mo ago
i think i normally use jose when i do jwt stuffs
Want results from more Discord servers?
Add your server