diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-26 15:47:37 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-03-14 13:58:44 +0100 |
| commit | a22ec1ee2833364839fae53cbbb4dc16030ed8ce (patch) | |
| tree | 9b406ef0ed76c1b3ca42254193b853cce569e146 | |
| parent | ebfdf9289aff8d85266161b17f490bc0a661ffcf (diff) | |
| download | mullvadvpn-a22ec1ee2833364839fae53cbbb4dc16030ed8ce.tar.xz mullvadvpn-a22ec1ee2833364839fae53cbbb4dc16030ed8ce.zip | |
Improve login call
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 11 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 24 |
2 files changed, 7 insertions, 28 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index ff0c81a707..055fadc4ef 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -264,10 +264,13 @@ export class DaemonRpc { await this.callString(this.client.loginAccount, accountToken); } catch (e) { const error = e as grpc.ServiceError; - if (error.code == grpc.status.RESOURCE_EXHAUSTED) { - throw new TooManyDevicesError(); - } else { - throw error; + switch (error.code) { + case grpc.status.RESOURCE_EXHAUSTED: + throw new TooManyDevicesError(); + case grpc.status.UNAUTHENTICATED: + throw new InvalidAccountError(); + default: + throw new CommunicationError(); } } } diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index b1f7f44b8a..da8f3afffb 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -107,8 +107,6 @@ enum AppQuitStage { ready, } -type AccountVerification = { status: 'verified' } | { status: 'deferred'; error: Error }; - class ApplicationMain { private notificationController = new NotificationController({ openApp: () => this.windowController?.show(), @@ -1481,12 +1479,6 @@ class ApplicationMain { private async login(accountToken: AccountToken): Promise<void> { try { - const verification = await this.verifyAccount(accountToken); - - if (verification.status === 'deferred') { - log.warn(`Failed to get account data, logging in anyway: ${verification.error.message}`); - } - await this.daemonRpc.loginAccount(accountToken); } catch (e) { const error = e as Error; @@ -1534,22 +1526,6 @@ class ApplicationMain { } } - private verifyAccount(accountToken: AccountToken): Promise<AccountVerification> { - return new Promise((resolve, reject) => { - this.accountDataCache.invalidate(); - this.accountDataCache.fetch(accountToken, { - onFinish: () => resolve({ status: 'verified' }), - onError: (error) => { - if (error instanceof InvalidAccountError) { - reject(error); - } else { - resolve({ status: 'deferred', error }); - } - }, - }); - }); - } - private updateAccountDataOnAccountChange(oldAccount?: string, newAccount?: string) { if (oldAccount && !newAccount) { this.accountDataCache.invalidate(); |
