Skip to content

Commit

Permalink
fixed error output if currentPassword is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutens committed Dec 12, 2024
1 parent 8e66a53 commit a9e6b9a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/constants/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const URLs = {
confirm: '/auth/confirm-email',
forgotPassword: '/auth/forgot-password',
resetPassword: '/auth/reset-password',
changePassword: '/auth/change-password',
validatePassword: '/auth/validate-password'
changePassword: '/auth/change-password'
},
users: {
get: '/users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,51 +51,16 @@ const ChangePasswordModal = () => {
title: 'titles.confirmTitle',
check: true
})
if (confirmed) {
resetErrors()
if (!confirmed) return
try {
await sendChangedPassword({
password: data.password,
currentPassword: data.currentPassword
})
} catch (err) {
data.currentPassword = ''
}
}
// const handleSubmitChangePassword = async () => {
// try {
// const response = await AuthService.validateCurrentPassword(
// userId,
// data.currentPassword
// )
// console.log(response)
// if (!response.data.isValid) {
// handleErrors(
// 'currentPassword',
// t('common.errorMessages.incorrectCurrentPassword')
// )
// return
// }
// const confirmed = await checkConfirmation({
// message: t(
// 'editProfilePage.profile.passwordSecurityTab.changePasswordConfirm'
// ),
// title: 'titles.confirmTitle',
// check: true,
// });
// if (!confirmed) {
// return;
// }
// resetErrors();
// await sendChangedPassword({
// password: data.password,
// currentPassword: data.currentPassword,
// });
// } catch (error) {
// console.error('Error during validateCurrentPassword:', error);
// handleErrors(
// 'currentPassword',
// t('common.errorMessages.incorrectCurrentPassword')
// );
// }
// }
const handleResponse = () => {
dispatch(
openAlert({
Expand Down Expand Up @@ -129,14 +94,12 @@ const ChangePasswordModal = () => {
const { loading, fetchData: sendChangedPassword } = useAxios({
service: changePassword,
onResponse: handleResponse,
// onResponseError: handleResponseError,
onResponseError: (error) => {
console.error('Error from service:', error)
onResponseError: (error: ErrorResponse) => {
handleResponseError(error)
throw error
},
fetchOnMount: false
})

const {
data,
handleSubmit,
Expand All @@ -151,7 +114,6 @@ const ChangePasswordModal = () => {
initialValues: initialValues,
validations: validations
})
console.log(errors)
const {
inputVisibility: currentPasswordVisibility,
showInputText: showCurrentPassword
Expand Down Expand Up @@ -195,7 +157,6 @@ const ChangePasswordModal = () => {
<Box sx={styles.form}>
<AppTextField
InputProps={currentPasswordVisibility}
// errorMsg={t(errors.currentPassword)}
errorMsg={errors.currentPassword ? t(errors.currentPassword) : ''}
fullWidth
label={t(
Expand Down
10 changes: 1 addition & 9 deletions src/services/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,11 @@ export const AuthService = {
changePassword: (
userId: string,
params: { password: string; currentPassword: string }
): Promise<AxiosResponse<null>> => {
): Promise<AxiosResponse> => {
return axiosClient.patch(
createUrlPath(URLs.auth.changePassword, userId),
params
)
},
validateCurrentPassword: (
userId: string,
currentPassword: string
): Promise<AxiosResponse<{ isValid: boolean }>> => {
console.log(currentPassword)
const url = createUrlPath(URLs.auth.validatePassword, userId)
return axiosClient.post(url, { currentPassword })
}
}

Expand Down

0 comments on commit a9e6b9a

Please sign in to comment.