A
Alokai10mo ago
ALI

custom query to change customer password

Hi, I'm trying to change password for an existing cutomer using graphql mutations. I have a vsf2nuxt3 app and I just implemented user authentication. Now, I want to implement change password feature for a user. I am trying changeCustomerPassword method from magento sdk. I am able to change password successfully but graphql returns me the fields that I do not require I want it to return the fields that I have written in my custom query. below is my code:
const changePasswordInput: ChangeCustomerPasswordInput = {
currentPassword: formData.value.currentPassword,
// eslint-disable-next-line unicorn/no-keyword-prefix
newPassword: formData.value.freshPassword,
};

try {
const { data } = await useAsyncData(() =>
useSdk().magento.changeCustomerPassword(changePasswordInput, {
customHeaders,
customQuery: passwordChangeCustomQuery,
}),
);
console.log(data, 'password changed!');
if (data.value?.errors) {
state.value.error = data.value.errors?.[0].message;
}
} catch (error) {
state.value.error = error as string;
}
const changePasswordInput: ChangeCustomerPasswordInput = {
currentPassword: formData.value.currentPassword,
// eslint-disable-next-line unicorn/no-keyword-prefix
newPassword: formData.value.freshPassword,
};

try {
const { data } = await useAsyncData(() =>
useSdk().magento.changeCustomerPassword(changePasswordInput, {
customHeaders,
customQuery: passwordChangeCustomQuery,
}),
);
console.log(data, 'password changed!');
if (data.value?.errors) {
state.value.error = data.value.errors?.[0].message;
}
} catch (error) {
state.value.error = error as string;
}
custom query:
export const passwordChangeCustomQuery: {
changeCustomerPassword: string;
metadata?: { fields: string };
} = {
changeCustomerPassword: 'password-change-custom-mutation',
metadata: {
fields: `
email
firstname
lastname
gender
id
addresses {
city
company
country_code
default_billing
default_shipping
id
postcode
region {
region
region_code
region_id
}
street
telephone
}
`,
},
};
export const passwordChangeCustomQuery: {
changeCustomerPassword: string;
metadata?: { fields: string };
} = {
changeCustomerPassword: 'password-change-custom-mutation',
metadata: {
fields: `
email
firstname
lastname
gender
id
addresses {
city
company
country_code
default_billing
default_shipping
id
postcode
region {
region
region_code
region_id
}
street
telephone
}
`,
},
};
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server