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:
The code in the onSuccess is executed.5 Replies
Has to be:
it is just meant for security purpose on not hoisting the error to your app instead it is logged on your server
For what reason? To not disclose the fact that the email doesn’t exist? Shouldn’t this be the app owner to decide what to disclose or not? I mean we should be able to catch the error and display that something went wrong instead of having a successful output on this
Wdyt?
For forgot password use cases, your app should display
"If your account exists, we've sent a password reset link to your email address"
we don’t expose whether the account exists to the client, to avoid email enumeration attacks
Rate limit is not applied to /forget-password path for some reason. Despite I have this custom rule: "/forget-password": {
window: 300,
max: 1,
},
I can send as many 'forget password emails' as I want as long as I provide existing email
I can throw custom error in hook:
And handle it on the client:
It displays the text of my error on the client in the toast
only in local dev though . It is a bit strange as it returns 204 in my case in prod but triggers onError callback. Does anyone knows why ?