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) {