I can't get forgot password to work, it throws 500 error
Link to reproduction
No response
Describe the Bug
when I try to fetch the token I get 500 error. I have posted this issue on Discord and Dan suggested that it could be a bug. This is my front end code: `import { NextApiRequest, NextApiResponse } from "next"; // import { getServerSession } from "next-auth/next";
// import { authOptions } from "./[...nextauth]";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'POST') {
try {
console.log('email ', req.body.email)
const result = await fetch(${process.env.CMS_URI}/api/users/forgot-password, {
method: 'POST',
credentials: 'include',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ email: req.body.email })
});
const data = await result.json();
console.log(data)
} catch (err) {
console.log(err)
}
} }`
This is the returned data { errors: [ { message: 'Something went wrong.' } ] }
And this error was thrown from the server
ERROR (payload): TypeError: Cannot read properties of undefined (reading 'email') at Object.generateEmailHTML (/Users/arthurmelkonyan/webdev/ethnicast-cms/payloadcms/src/collections/Users/index.ts:24:32) at forgotPassword (/Users/arthurmelkonyan/webdev/ethnicast-cms/payloadcms/node_modules/payload/src/auth/operations/forgotPassword.ts:112:59) at processTicksAndRejections (node:internal/process/task_queues:95:5) at forgotPasswordHandler (/Users/arthurmelkonyan/webdev/ethnicast-cms/payloadcms/node_modules/payload/src/auth/requestHandlers/forgotPassword.ts:15:5)
To Reproduce
I have created the form on the front end to capture the email and pass to API Route handler
Payload Version
v2
Adapters and Plugins
No response
Hey @artmelkon, Have you configured the mail service like smtp in the payload init?
await payload.init({
secret: process.env.PAYLOAD_SECRET,
express: app,
email: {
transportOptions: transportOptions,
fromName: process.env.MAIL_FROM_NAME,
fromAddress: process.env.MAIL_FROM_ADDRESS,
},
});
Hi faizur11786. Yes, I have done it and I don't think it has to do with that. That configuration didn't work for me, throwing error saying that email wasn't configured right, basically it was a mail server issue. So, I'm using "nodemailer-sendgrid-transport module ", tested and it works perfectly fine. I don't think that it's related to SMPT configuration as the error thrown for the server tells that " undefined (reading 'email')"
I fixed it and it works.
Hey @artmelkon - are you still experiencing this issue or has it been resolved?
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.