From 594c869906e0a232c05363fdc82c339ab3482de6 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Mon, 13 Jan 2025 13:47:58 +0100 Subject: [PATCH] fix(ui): user invitation --- .../ForgotPassword/CreatePassword.tsx | 10 ++------- frontend/app/mstore/userStore.ts | 2 ++ frontend/app/services/UserService.ts | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/frontend/app/components/ForgotPassword/CreatePassword.tsx b/frontend/app/components/ForgotPassword/CreatePassword.tsx index 17193828e..a943da41c 100644 --- a/frontend/app/components/ForgotPassword/CreatePassword.tsx +++ b/frontend/app/components/ForgotPassword/CreatePassword.tsx @@ -32,13 +32,7 @@ function CreatePassword(props: Props) { if (!validatePassword(password)) { return; } - resetPassword({ invitation, pass, password }).then((response: any) => { - if (response && response.errors && response.errors.length > 0) { - setError(response.errors[0]); - } else { - setUpdated(true); - } - }); + void resetPassword({ invitation, pass, password }); }; const onSubmit = (e: any) => { @@ -102,7 +96,7 @@ function CreatePassword(props: Props) { /> - + { this.account = new Account(data.user); + this.jwt = data.jwt; + this.spotJwt = data.spotJwt; }); } catch (error) { toast.error('Error resetting your password; please try again'); diff --git a/frontend/app/services/UserService.ts b/frontend/app/services/UserService.ts index ca8886217..1dabe0e00 100644 --- a/frontend/app/services/UserService.ts +++ b/frontend/app/services/UserService.ts @@ -136,11 +136,23 @@ export default class UserService { .then((response: { data: any }) => response as Record || {}); } - resetPassword(data: any) { - return this.client - .post('/password/reset', data) - .then((response: { json: () => any }) => response.json()) - .then((response: { data: any }) => response.data || {}); + async resetPassword(data: any) { + try { + const response = await this.client.post('/password/reset', data); + const responseData = await response.json(); + if (responseData.errors) { + throw new Error(responseData.errors[0] || 'An unexpected error occurred.'); + } + + return responseData || {}; + } catch (error: any) { + if (error.response) { + const errorData = await error.response.json(); + const errorMessage = errorData.errors ? errorData.errors[0] : 'An unexpected error occurred.'; + throw new Error(errorMessage); + } + throw new Error('An unexpected error occurred.'); + } } async requestResetPassword(data: any) {