diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-09-07 17:57:31 +0300 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-09-10 17:55:41 +0300 |
| commit | 35cb43ea97ff4c82dc981d3c06093e904a85831a (patch) | |
| tree | 4b7e133bb3b6dea19b19d354b08e98f964139346 | |
| parent | 854e3ae2e4fdfefb0c56faa56807e5e163238542 (diff) | |
| download | mullvadvpn-35cb43ea97ff4c82dc981d3c06093e904a85831a.tar.xz mullvadvpn-35cb43ea97ff4c82dc981d3c06093e904a85831a.zip | |
Store accountToken in App
| -rw-r--r-- | gui/packages/desktop/src/renderer/app.js | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js index 04cbc9f6da..53fea2151e 100644 --- a/gui/packages/desktop/src/renderer/app.js +++ b/gui/packages/desktop/src/renderer/app.js @@ -48,6 +48,7 @@ export default class AppRenderer { _reduxActions: *; _accountDataState = new AccountDataState(); _connectedToDaemon = false; + _accountToken: ?AccountToken; _tunnelState: ?TunnelState; constructor() { @@ -140,6 +141,9 @@ export default class AppRenderer { const accountData = await this._daemonRpc.getAccountData(accountToken); await this._daemonRpc.setAccount(accountToken); + // reset the account token with the one that we just sent to daemon + this._accountToken = accountToken; + actions.account.updateAccountExpiry(accountData.expiry); actions.account.loginSuccessful(); @@ -172,6 +176,9 @@ export default class AppRenderer { const accountToken = await this._daemonRpc.getAccount(); + // save the account token received after connecting to daemon + this._accountToken = accountToken; + if (accountToken) { log.debug(`Got account token: ${accountToken}`); actions.account.updateAccountToken(accountToken); @@ -215,6 +222,10 @@ export default class AppRenderer { try { await this._daemonRpc.setAccount(null); + + // reset the account token after log out + this._accountToken = null; + await this._fetchAccountHistory(); actions.account.loggedOut(); @@ -230,12 +241,6 @@ export default class AppRenderer { async connectTunnel() { const actions = this._reduxActions; - // avoid connecting when there is no account set in daemon. - const accountToken = await this._daemonRpc.getAccount(); - if (!accountToken) { - throw new NoAccountError(); - } - // connect only if tunnel is disconnected or blocked. if ( this._tunnelState && @@ -317,19 +322,14 @@ export default class AppRenderer { } try { - const accountToken = await this._daemonRpc.getAccount(); - if (!accountToken) { - throw new NoAccountError(); - } - - const accountData = await accountDataState.update(() => { - return this._daemonRpc.getAccountData(accountToken); - }); - - // Check if account token is still the same after receiving account data - const currentAccountToken = this._reduxStore.getState().account.accountToken; - if (currentAccountToken === accountToken) { + const accountToken = this._accountToken; + if (accountToken) { + const accountData = await accountDataState.update(() => { + return this._daemonRpc.getAccountData(accountToken); + }); actions.account.updateAccountExpiry(accountData.expiry); + } else { + throw new NoAccountError(); } } catch (e) { log.error(`Failed to update account expiry: ${e.message}`); @@ -477,12 +477,19 @@ export default class AppRenderer { // auto connect the tunnel on startup // note: disabled when developing if (process.env.NODE_ENV !== 'development') { - try { - log.debug('Auto-connecting the tunnel...'); - await this.connectTunnel(); - } catch (error) { - log.error(`Failed to auto-connect the tunnel: ${error.message}`); + // only connect if account is set in the daemon + if (this._accountToken) { + try { + log.debug('Autoconnect the tunnel'); + await this.connectTunnel(); + } catch (error) { + log.error(`Failed to autoconnect the tunnel: ${error.message}`); + } + } else { + log.debug('Skip autoconnect because account token is not set'); } + } else { + log.debug('Skip autoconnect in development'); } } |
