Resend for /api/users/forgot-password over REST in Vercel
Resend does not receive email request on Vercel. Locally no issues.
Version:
"@payloadcms/email-resend": "3.0.0-beta.25"
payload.config.ts
import { resendAdapter } from '@payloadcms/email-resend'
export default buildConfig({
email: resendAdapter({
defaultFromAddress: '****@****.****.com',
defaultFromName: 'Payload CMS',
apiKey: '**********',
}),
....
REST Call
await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/users/forgot-password`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '****@****.****.com',
}),
});
Users: CollectionConfig
...
auth: {
forgotPassword: {
generateEmailSubject: () => 'Reset your password',
generateEmailHTML: async ({ req, token, user }: any) => {
const resetPasswordURL = `${process.env.NEXT_PUBLIC_BASE_URL}/verify?token=${token}`
return `
<!doctype html>
<html>
<body>
<h1>Here is my custom email template!</h1>
<p>Hello, ${user.email}!</p>
<p>Click below to reset your password.</p>
<p>
<a href="${resetPasswordURL}">${resetPasswordURL}</a>
</p>
</body>
</html>
`
},
},
},
Note: Same issue exists without using forgotPassword.generateEmailHTML within User collection > auth
Is this just over the REST API? What response are you getting from that fetch if so? It doesn't look like you're sending any creds.
Does the Forgot password? link on the login page send the email to you as expected?
All of the normal functionality appears to work for me.
When you say "It doesn't look like you're sending any creds.", am I incorrect in thinking that the correct way of providing creds is through the payload config for the resendAdapter. Outside of that, forgot password should only require an email no?
This is related to REST. I will follow up with OOTB forgot password.
Thanks for your prompt reply BTW
Further testing for me, neither REST nor /admin forgot password link works on Vercel. Can you see an issue with my implementation in the config?
"@payloadcms/email-resend": "3.0.0-beta.25",
import { resendAdapter } from '@payloadcms/email-resend'
export default buildConfig({
email: resendAdapter({
defaultFromAddress: '****@****.****.com',
defaultFromName: 'Payload CMS',
apiKey: '**********',
}),
....
Is this just over the REST API? What response are you getting from that fetch if so? It doesn't look like you're sending any creds.
Does the
Forgot password?link on the login page send the email to you as expected?All of the normal functionality appears to work for me.
Interesting reset hyperlinked text though.... undefined
Tried with @payloadcms/email-nodemailer just now. Unfortunately same result. Locally works perfect, Vercel, nothing gets through. Tried on Vercel edge and without. Followed the docs for transportOptions here:
https://www.npmjs.com/package/@payloadcms/email-nodemailer
@JarrodMFlesch I just simply didn't set the variable from the template provided in the example.
@peterjunsworth
What response are you getting from that fetch if so? It doesn't look like you're sending any creds.
I would expect to see some sort of Payload auth credentials being sent in the REST request in order to be able to invoke this route. Where are you actually calling this function from? Your front-end? A local script? Different server?
Does the Forgot password? link on the login page send the email to you as expected?
Just want to verify that this still works for you. I know this is not the same as your REST request, but it just helps troubleshooting.
I am invoking forgotPassword from the NextJS (app) custom login page:
const forgotPassword = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/users/forgot-password`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: normailizedEmail,
}),
});
const fp = await forgotPassword.json();
console.log(fp);
Response:
{ message: 'Success' }
I am unclear about 'Payload auth credentials' for forgot password endpoint, isn't this anonymous?
Does the Forgot password? link on the login page send the email to you as expected?
Only locally
@peterjunsworth Can you provide a minimal reproduction repo? The forgot password link not working for you is most concerning to me, as this works just fine in my testing.
@denolfe - just invited you to a fork of the repo. Added a couple of notes to top of readme
Everything fine and works as expected locally. Just vercel deployment no emails for me
@denolfe - no worries if you haven't looked at this yet but I did see you forked the repo so thought I would check-in to see if you were able to replicate with that repo?
@peterjunsworth The repo was a bit large, would appreciate a smaller reproduction that I can simply load and click something to reproduce.
@peterjunsworth Could you simplify your reproduction?
@denolfe - ye - I will do but under the gun right now so haven't had the opportunity yet
ok @denolfe - finally got round to it. Just added you to the repo (let me know if didn't receive invite). I forked this repo from: https://github.com/payloadcms/payload-3.0-demo
You will see the resend dependencies in the package.json file. Locally I receive email, deployed to Vercel 'nothing', just a success message in network. Same even using the admin forgot password functionality: https://payloadtestingemail.vercel.app/admin/forgot
Very simple setup using Mongo Atlas and @payloadcms/email-resend": "^3.0.0-beta.40" Nothing much else configured apart from what was in the original repo.
Hopefully I am just missing something minor.
Cheers
No error messages in Vercel or browser No logs at all in resend - double checked env vars
Will have a fix going out in the next beta for this 👍
awesome - thanks. glad it wasn't just me being daft
@peterjunsworth These email calls should now be awaited. Try it out on beta.46 and let me know 👍
https://github.com/payloadcms/payload/releases/tag/v3.0.0-beta.46
Fantastic - thanks @denolfe . I will definitely give it a try. Thank you for addressing
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.
