diff --git a/packages/common/src/services/StorageService.ts b/packages/common/src/services/StorageService.ts index f52f0be26..9333edc18 100644 --- a/packages/common/src/services/StorageService.ts +++ b/packages/common/src/services/StorageService.ts @@ -5,7 +5,7 @@ export default abstract class StorageService { abstract setItem(key: string, value: string, usePrefix?: boolean): Promise; - abstract removeItem(key: string): Promise; + abstract removeItem(key: string, usePrefix?: boolean): Promise; abstract base64Decode(input: string): string; diff --git a/packages/common/src/services/integrations/jwp/JWPAPIService.ts b/packages/common/src/services/integrations/jwp/JWPAPIService.ts index 86439a7e0..3ecbcb9e1 100644 --- a/packages/common/src/services/integrations/jwp/JWPAPIService.ts +++ b/packages/common/src/services/integrations/jwp/JWPAPIService.ts @@ -51,7 +51,7 @@ export default class JWPAPIService { }; removeToken = async () => { - await Promise.all([this.storageService.removeItem(INPLAYER_TOKEN_KEY), this.storageService.removeItem(INPLAYER_IOT_KEY)]); + await Promise.all([this.storageService.removeItem(INPLAYER_TOKEN_KEY, false), this.storageService.removeItem(INPLAYER_IOT_KEY, false)]); }; isAuthenticated = async () => { diff --git a/packages/ui-react/src/containers/AccountModal/forms/EditPassword.tsx b/packages/ui-react/src/containers/AccountModal/forms/EditPassword.tsx index 22c54a2ba..0b5fb8032 100644 --- a/packages/ui-react/src/containers/AccountModal/forms/EditPassword.tsx +++ b/packages/ui-react/src/containers/AccountModal/forms/EditPassword.tsx @@ -32,25 +32,28 @@ const ResetPassword = ({ type }: { type?: 'add' }) => { return setSubmitting(false); } - let resetToken = resetPasswordTokenParam; - if (resetPasswordToken) { - resetToken = resetPasswordToken; - } + + const resetToken = resetPasswordToken || resetPasswordTokenParam; + try { - if (user && !resetToken) { - await accountController.changePasswordWithOldPassword(oldPassword || '', password, passwordConfirmation); + let pathname = location.pathname; + + if (resetToken) { + await accountController.changePasswordWithToken(emailParam || '', password, resetToken, passwordConfirmation); } else { - if (!resetToken) { + if (!user) { setErrors({ form: t('reset.invalid_link') }); - return setSubmitting(false); } - await accountController.changePasswordWithToken(emailParam || '', password, resetToken, passwordConfirmation); + + pathname = '/'; + + await accountController.changePasswordWithOldPassword(oldPassword || '', password, passwordConfirmation); + await accountController.logout(); } announce(t('reset.password_reset_success'), 'success'); - await accountController.logout(); - navigate(modalURLFromLocation(location, 'login')); + navigate(modalURLFromLocation({ ...location, pathname }, 'login')); } catch (error: unknown) { if (error instanceof Error) { if (error.message.includes('invalid param password')) { diff --git a/platforms/web/src/services/LocalStorageService.ts b/platforms/web/src/services/LocalStorageService.ts index eee2c5d6a..1e92b3ff3 100644 --- a/platforms/web/src/services/LocalStorageService.ts +++ b/platforms/web/src/services/LocalStorageService.ts @@ -10,8 +10,8 @@ export class LocalStorageService extends StorageService { this.prefix = prefix; } - getStorageKey(key: string) { - return `${this.prefix}.${key}`; + getStorageKey(key: string, usePrefix = true) { + return usePrefix ? `${this.prefix}.${key}` : key; } async getItem(key: string, parse: boolean, usePrefix = true) { @@ -32,9 +32,9 @@ export class LocalStorageService extends StorageService { } } - async removeItem(key: string) { + async removeItem(key: string, usePrefix = true) { try { - window.localStorage.removeItem(this.getStorageKey(key)); + window.localStorage.removeItem(this.getStorageKey(key, usePrefix)); } catch (error: unknown) { logError('LocalStorageService', 'Failed to remove localStorage entry', { error }); }