Skip to content

Commit

Permalink
stop removing persisted "proton session" on login form showing
Browse files Browse the repository at this point in the history
* Sometimes the login form gets displayed due to the network connection issues, this is how proton-webclients got implemented (they probably set up and track of the respective timeouts). So the login form might get displayed not only because the session got nuked/expired.
* So thi change leaves the only remaining way to remove the persistent session from encrypted "session.bin" file: explicit disabling the respective "persistent session" toggle on the account edit form ("extended options" collapsible section on the form).
  • Loading branch information
vladimiry committed Mar 5, 2020
1 parent d0e7ef3 commit 08f79ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Expand Up @@ -3,7 +3,7 @@ import {Subject, from, race} from "rxjs";
import {distinctUntilChanged, filter, map, pairwise, take, takeUntil, withLatestFrom} from "rxjs/operators";
import {equals, pick} from "remeda";

import {ACCOUNTS_ACTIONS, NOTIFICATION_ACTIONS} from "src/web/browser-window/app/store/actions";
import {ACCOUNTS_ACTIONS} from "src/web/browser-window/app/store/actions";
import {AccountConfig} from "src/shared/model/account";
import {AccountViewAbstractComponent} from "src/web/browser-window/app/_accounts/account-view-abstract.component";
import {WEB_CLIENTS_BLANK_HTML_FILE_NAME} from "src/shared/constants";
Expand Down Expand Up @@ -123,21 +123,6 @@ export class AccountViewPrimaryComponent extends AccountViewAbstractComponent im
).subscribe((account) => {
this.event.emit({type: "log", data: ["info", `onWebViewMounted(): dispatch "TryToLogin"`]});
this.event.emit({type: "action", payload: ACCOUNTS_ACTIONS.TryToLogin({account, webView})});

// removing possibly persisted "proton session" on login form showing
(async () => {
const {accountConfig, notifications} = account;
const resetSavedProtonSession = notifications.pageType.type === "login" && accountConfig.persistentSession;
if (!resetSavedProtonSession) {
return;
}
const parsedEntryUrl = this.core.parseEntryUrl(accountConfig, "WebClient");
const key = {login: accountConfig.login, apiEndpointOrigin: new URL(parsedEntryUrl.entryApiUrl).origin} as const;
await this.api.ipcMainClient()("resetSavedProtonSession")(key);
})().catch((error) => {
// TODO make "AppErrorHandler.handleError" catch promise rejection errors
this.event.emit({type: "action", payload: NOTIFICATION_ACTIONS.Error(error)});
});
}),
);

Expand Down
37 changes: 32 additions & 5 deletions src/web/browser-window/app/_accounts/account.component.ts
Expand Up @@ -18,6 +18,7 @@ import {
distinctUntilChanged,
filter,
map,
mergeMap,
pairwise,
startWith,
switchMap,
Expand Down Expand Up @@ -94,6 +95,11 @@ export class AccountComponent extends NgChangesObservableComponent implements On
take(1),
);

private readonly persistentSession$ = this.account$.pipe(
map(({accountConfig: {persistentSession}}) => Boolean(persistentSession)),
distinctUntilChanged(),
);

// TODO resolve "componentIndex" dynamically: accounts$.indexOf(({login}) => this.login === login)
private readonly componentIndex: number;

Expand Down Expand Up @@ -235,6 +241,31 @@ export class AccountComponent extends NgChangesObservableComponent implements On
});
}),
);

// removing "proton session" on "persistent session" toggle gets disabled notification
// WARN don't put this logic in "onPrimaryViewLoadedOnce" since it should work in offline mode too
this.subscription.add(
this.persistentSession$
.pipe(
mergeMap((persistentSession) => persistentSession ? [] : [persistentSession]),
withLatestFrom(this.account$),
)
.subscribe(([persistentSession, {accountConfig}]) => {
(async () => {
if (persistentSession) { // just extra check
throw new Error(`"persistentSession" value is supposed to be "false" here`);
}

const parsedEntryUrl = this.core.parseEntryUrl(accountConfig, "WebClient");
const key = {login: accountConfig.login, apiEndpointOrigin: new URL(parsedEntryUrl.entryApiUrl).origin} as const;

await this.api.ipcMainClient()("resetSavedProtonSession")(key);
})().catch((error) => {
// TODO make "AppErrorHandler.handleError" catch promise rejection errors
this.onDispatchInLoggerZone(NOTIFICATION_ACTIONS.Error(error));
});
}),
);
}

onEventChild(
Expand Down Expand Up @@ -270,10 +301,7 @@ export class AccountComponent extends NgChangesObservableComponent implements On
distinctUntilChanged(),
),
// notification: toggling "persistentSession" flag on the account edit form
this.account$.pipe(
map(({accountConfig: {persistentSession}}) => Boolean(persistentSession)),
distinctUntilChanged(),
),
this.persistentSession$,
]).pipe(
withLatestFrom(this.account$),
).subscribe(([[loggedIn, persistentSession], {accountConfig}]) => {
Expand All @@ -282,7 +310,6 @@ export class AccountComponent extends NgChangesObservableComponent implements On
const key = {login: accountConfig.login, apiEndpointOrigin: new URL(parsedEntryUrl.entryApiUrl).origin} as const;

if (!persistentSession) {
await this.api.ipcMainClient()("resetSavedProtonSession")(key);
return;
}

Expand Down

0 comments on commit 08f79ec

Please sign in to comment.