mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
Error handling for invalid users
This commit is contained in:
@ -29,9 +29,28 @@ export default function ForgotPassword() {
|
|||||||
loading: "Sending...",
|
loading: "Sending...",
|
||||||
success: `Reset link sent. `,
|
success: `Reset link sent. `,
|
||||||
error: "Could not send reset link :/",
|
error: "Could not send reset link :/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
minWidth: "200px",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
toast.dismiss();
|
||||||
|
|
||||||
|
if (response.status == 400 || response.status == 404) {
|
||||||
|
toast.error("Email address not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status == 500) {
|
||||||
|
toast.error("Something went wrong.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setResetSuccessful(true);
|
setResetSuccessful(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,16 +20,23 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(400).json({ message: "No user found with this email." });
|
return res.status(404).json({ message: "No user found with this email." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = crypto.randomBytes(64).toString("hex");
|
const token = crypto.randomBytes(64).toString("hex");
|
||||||
const passwordResetToken = await prisma.passwordResetToken.create({
|
|
||||||
data: {
|
let passwordResetToken;
|
||||||
token,
|
|
||||||
userId: user.id,
|
try {
|
||||||
},
|
passwordResetToken = await prisma.passwordResetToken.create({
|
||||||
});
|
data: {
|
||||||
|
token,
|
||||||
|
userId: user.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(500).json({ message: "Error saving token." });
|
||||||
|
}
|
||||||
|
|
||||||
await sendResetPassword(user, passwordResetToken.token);
|
await sendResetPassword(user, passwordResetToken.token);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user