Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWA-99: fix: do not perform logout if password reset with token #648

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]);
AntonLantukh marked this conversation as resolved.
Show resolved Hide resolved
};

isAuthenticated = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ 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);
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);

await accountController.changePasswordWithOldPassword(oldPassword || '', password, passwordConfirmation);
AntonLantukh marked this conversation as resolved.
Show resolved Hide resolved
await accountController.logout();
}

announce(t('reset.password_reset_success'), 'success');
await accountController.logout();
navigate(modalURLFromLocation(location, 'login'));
} catch (error: unknown) {
if (error instanceof Error) {
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
Loading