Skip to content

Commit

Permalink
fix: do not perform logout if password reset with token (#648)
Browse files Browse the repository at this point in the history
* fix: do not perform logout if password reset with token
* fix: redirect to index page after reset password with old password
  • Loading branch information
mirovladimitrovski authored Dec 6, 2024
1 parent 7ee979e commit c3fbdc9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/services/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default abstract class StorageService {

abstract setItem(key: string, value: string, usePrefix?: boolean): Promise<void>;

abstract removeItem(key: string): Promise<void>;
abstract removeItem(key: string, usePrefix?: boolean): Promise<void>;

abstract base64Decode(input: string): string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
8 changes: 4 additions & 4 deletions platforms/web/src/services/LocalStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 });
}
Expand Down

0 comments on commit c3fbdc9

Please sign in to comment.