maito
maito
BABetter Auth
Created by maito on 4/13/2025 in #help
Handling error of forgetPassword call
Hi, I'm trying to handle the error when using forgetPassword but if I provide an email which is unknown, I can't catch the error. I'm seing this in the output: 2025-04-13T20:05:20.175Z ERROR [Better Auth]: Reset Password: User not found { email: '[email protected]' } Here is my code:
const handleResetRequest = async () => {
setLoading(true);
const response = await authClient.forgetPassword({ email, redirectTo: "/auth/forget-password" }, {
onError: (error) => {
toast.error(error.error.message);
},
onSuccess: () => {
toast.success("Password reset email sent! Check your inbox.");
router.push("/auth/login");
}
});
};
const handleResetRequest = async () => {
setLoading(true);
const response = await authClient.forgetPassword({ email, redirectTo: "/auth/forget-password" }, {
onError: (error) => {
toast.error(error.error.message);
},
onSuccess: () => {
toast.success("Password reset email sent! Check your inbox.");
router.push("/auth/login");
}
});
};
The code in the onSuccess is executed.
8 replies