-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Describe the Bug
When sending email fails, for example due to bad credentials, POST /api/admins/forgot-password
does correctly return a 500 error, but the built-in UI still shows a success in that case, it claims the email was sent when it actually wasn't, and the user is none the wiser.
Note that I do not mean the case where the email does not exist in the database, I'm talking about a server misconfiguration, problem with the email server, etc.

Root Cause
The issue is here (no check for response.ok
):
payload/packages/next/src/views/ForgotPassword/ForgotPasswordForm/index.tsx
Lines 25 to 39 in 1072171
const handleResponse: FormProps['handleResponse'] = (res, successToast, errorToast) => { | |
res | |
.json() | |
.then(() => { | |
setHasSubmitted(true) | |
successToast(t('general:submissionSuccessful')) | |
}) | |
.catch(() => { | |
errorToast( | |
loginWithUsername | |
? t('authentication:usernameNotValid') | |
: t('authentication:emailNotValid'), | |
) | |
}) | |
} |
Link to the code that reproduces this issue
unnecessary, any app will do once you change the email config to a bad one
Reproduction Steps
Create a blank project, set some bad email configuration in it that isn't blank, for example some SMTP configuration with bad credentials. Then try to use the forgot password form.
Which area(s) are affected? (Select all that apply)
area: ui
Environment Info
Irrelevant