Skip to content

Commit f6827c5

Browse files
authored
fix(theme): fix customer account update data and password change functionality (#469)
- Previously error and success messages were not displayed and the change password action always lead to an error, now either update data and password change are handled properly Co-authored-by: Bartosz Herba <[email protected]>
1 parent 806f1ba commit f6827c5

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

packages/composables/src/composables/useUser/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ CustomerCreateInput
139139
changePassword: async (context: Context, params) => {
140140
Logger.debug('[Magento] changing user password');
141141
const { data, errors } = await context.$magento.api.changeCustomerPassword(params);
142-
143142
if (errors) {
144143
Logger.error(errors);
145-
146144
throw new Error(errors.map((e) => e.message).join(','));
147145
}
148146

packages/theme/components/MyAccount/PasswordResetForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export default defineComponent({
101101
resetValidationFn();
102102
};
103103
104-
const onError = () => {
104+
const onError = (msg) => {
105105
sendNotification({
106106
id: Symbol('password_not_updated'),
107-
message: 'It was not possible to update your password.',
107+
message: msg,
108108
type: 'danger',
109109
icon: 'cross',
110110
persist: false,

packages/theme/pages/MyAccount/MyProfile.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ export default defineComponent({
7979
load,
8080
loading,
8181
updateUser,
82+
error,
8283
} = useUser();
8384
8485
const formHandler = async (fn, onComplete, onError) => {
85-
try {
86-
const data = await fn();
87-
if (!data) throw new Error('API Error');
88-
await onComplete(data);
89-
} catch (error) {
90-
onError(error);
86+
await fn();
87+
if (error.value.changePassword !== null) {
88+
onError(error.value.changePassword);
89+
} else {
90+
onComplete();
9191
}
9292
};
9393
@@ -100,13 +100,14 @@ export default defineComponent({
100100
onComplete,
101101
onError,
102102
);
103+
103104
const updatePassword = ({
104105
form,
105106
onComplete,
106107
onError,
107108
}) => formHandler(async () => changePassword({
108-
currentPassword: form.value.currentPassword,
109-
newPassword: form.value.newPassword,
109+
current: form.value.currentPassword,
110+
new: form.value.newPassword,
110111
}), onComplete, onError);
111112
112113
onSSR(async () => {

0 commit comments

Comments
 (0)