diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-11-30 17:35:39 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-06 13:36:25 +0100 |
| commit | 07a007976410a5fbaafe1e893125cbb9b25f993f (patch) | |
| tree | 457dd17936742bb8a77efdfd87ec0ccd66e5360c /app/lib | |
| parent | 9ce419928e84d11a2fc487f0b0565427aa79b1a8 (diff) | |
| download | mullvadvpn-07a007976410a5fbaafe1e893125cbb9b25f993f.tar.xz mullvadvpn-07a007976410a5fbaafe1e893125cbb9b25f993f.zip | |
Convert Backend.autologout() to async
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/backend.js | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index 0621a24338..af559c3c16 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -223,38 +223,35 @@ export class Backend { }); } - autologin() { - log.debug('Attempting to log in automatically'); + async autologin() { + try { + log.debug('Attempting to log in automatically'); - this._store.dispatch(accountActions.startLogin()); + await this._ensureAuthenticated(); - return this._ensureAuthenticated() - .then( () => { - return this._ipc.getAccount() - .then( accountToken => { - if (!accountToken) { - throw new BackendError('NO_ACCOUNT'); - } - log.debug('The backend had an account number stored:', accountToken); - this._store.dispatch(accountActions.startLogin(accountToken)); + this._store.dispatch(accountActions.startLogin()); - return this._ipc.getAccountData(accountToken); - }) - .then( accountData => { - log.debug('The stored account number still exists', accountData); + const accountToken = await this._ipc.getAccount(); + if(!accountToken) { + throw new BackendError('NO_ACCOUNT'); + } - this._store.dispatch(accountActions.loginSuccessful(accountData.expiry)); - return this._store.dispatch(push('/connect')); - }) - .catch( e => { - log.warn('Unable to autologin,', e.message); + log.debug('The backend had an account number stored: ', accountToken); + this._store.dispatch(accountActions.startLogin(accountToken)); - this._store.dispatch(accountActions.autoLoginFailed()); - this._store.dispatch(push('/')); + const accountData = await this._ipc.getAccountData(accountToken); + log.debug('The stored account number still exists', accountData); - throw e; - }); - }); + this._store.dispatch(accountActions.loginSuccessful(accountData.expiry)); + this._store.dispatch(push('/connect')); + } catch (e) { + log.warn('Unable to autologin,', e.message); + + this._store.dispatch(accountActions.autoLoginFailed()); + this._store.dispatch(push('/')); + + throw e; + } } logout() { |
