From 5ada4986ac18626ca994a98c19a4c1abcdf8b2c0 Mon Sep 17 00:00:00 2001 From: Yuna Kim Date: Thu, 27 Oct 2022 16:42:32 -0400 Subject: [PATCH 1/2] Restart SLAS login after pw change --- .../app/commerce-api/hooks/useCustomer.js | 11 ++++++++++- .../app/pages/account/profile.jsx | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js b/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js index f8b6b9b984..a7e32851f5 100644 --- a/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js +++ b/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js @@ -175,8 +175,9 @@ export default function useCustomer() { * @param {object} data * @param {string} data.currentPassword - The old password. * @param {string} data.password - The new password. + * @param {string} email - Customer's email */ - async updatePassword(data) { + async updatePassword(data, email) { const body = { password: data.password, currentPassword: data.currentPassword @@ -200,6 +201,14 @@ export default function useCustomer() { throw new Error(json.detail) } } + + // Send a new login request with updated password + const credentials = { + email: email, + password: data.password + } + + await self.login(credentials) }, /** diff --git a/packages/template-retail-react-app/app/pages/account/profile.jsx b/packages/template-retail-react-app/app/pages/account/profile.jsx index dbf6140df2..ab44aa6d79 100644 --- a/packages/template-retail-react-app/app/pages/account/profile.jsx +++ b/packages/template-retail-react-app/app/pages/account/profile.jsx @@ -197,7 +197,7 @@ const PasswordCard = () => { const submit = async (values) => { try { form.clearErrors() - await customer.updatePassword(values) + await customer.updatePassword(values, customer.email) setIsEditing(false) toast({ title: formatMessage({ From c5262c3bce757426d29f8e520ec2cd5f15a26f57 Mon Sep 17 00:00:00 2001 From: Yuna Kim Date: Fri, 28 Oct 2022 11:07:38 -0400 Subject: [PATCH 2/2] Update comment --- .../app/commerce-api/hooks/useCustomer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js b/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js index a7e32851f5..e7d9b67f11 100644 --- a/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js +++ b/packages/template-retail-react-app/app/commerce-api/hooks/useCustomer.js @@ -202,7 +202,7 @@ export default function useCustomer() { } } - // Send a new login request with updated password + // Fetch a new SLAS JWT to update the invalid one in client app state const credentials = { email: email, password: data.password