Skip to content

Commit 989cb97

Browse files
committed
Error message when reset password is used is generic #93
1 parent 0994775 commit 989cb97

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/ResetPassword.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ export const ResetPassword = ({ email }: { email: IGetUser['email'] }) => {
3636
toast.success('Password changed successfully.');
3737
setState(initialState);
3838
},
39-
onError: (error) => toast.error(`Something went wrong: ${error.message}`),
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40+
onError: (error: any) => {
41+
// Try to extract and display password validation errors from the response
42+
const apiErrors = error?.response?.data;
43+
if (apiErrors && typeof apiErrors === 'object') {
44+
const messages = Object.values(apiErrors).flat().join('\n');
45+
toast.error(messages, {
46+
style: { whiteSpace: 'pre-line', minWidth: 560 },
47+
duration: 7000,
48+
});
49+
} else {
50+
toast.error(`Something went wrong: ${error.message}`);
51+
}
52+
return;
53+
},
4054
});
4155

4256
const handleOnChange = (event: ChangeEvent<HTMLTextAreaElement>) =>
@@ -58,7 +72,10 @@ export const ResetPassword = ({ email }: { email: IGetUser['email'] }) => {
5872
}
5973

6074
if (password !== confirmPassword) {
61-
toast.error('The new password does not match the confirmed password.');
75+
toast.error('The new password does not match the confirmed password.', {
76+
style: { whiteSpace: 'pre-line', minWidth: 530 },
77+
duration: 7000,
78+
});
6279
return;
6380
}
6481

0 commit comments

Comments
 (0)