Skip to content

Commit

Permalink
feat(core): add change password mutation for logged in customer
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi committed Mar 20, 2024
1 parent 43b1afd commit e64a22b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-rocks-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

add change password mutation for logged in customer
56 changes: 56 additions & 0 deletions apps/core/client/mutations/submit-customer-change-password.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { z } from 'zod';

import { client } from '..';
import { graphql } from '../graphql';

export const ChangePasswordSchema = z
.object({
currentPassword: z.string(),
newPassword: z.string(),
})
.required();

type SubmitCustomerChangePassword = z.infer<typeof ChangePasswordSchema>;

const SUBMIT_CUSTOMER_CHANGE_PASSWORD_MUTATION = graphql(`
mutation CustomerChangePassword($input: ChangePasswordInput!) {
customer {
changePassword(input: $input) {
errors {
... on ValidationError {
message
path
}
... on CustomerDoesNotExistError {
message
}
... on CustomerPasswordError {
message
}
... on CustomerNotLoggedInError {
message
}
}
}
}
}
`);

export const submitCustomerChangePassword = async ({
currentPassword,
newPassword,
}: SubmitCustomerChangePassword) => {
const variables = {
input: {
currentPassword,
newPassword,
},
};

const response = await client.fetch({
document: SUBMIT_CUSTOMER_CHANGE_PASSWORD_MUTATION,
variables,
});

return response.data.customer.changePassword;
};

0 comments on commit e64a22b

Please sign in to comment.