summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-08-01 13:30:55 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-08-08 15:26:34 +0200
commit21c62239a0ef590e77f3a5a3448f36259755d6d8 (patch)
tree8cde7e5e8cca7580e89f154c4b39d893f8275949
parentd53fda746465c0bb6525371b9d780cbfac90f942 (diff)
downloadmullvadvpn-21c62239a0ef590e77f3a5a3448f36259755d6d8.tar.xz
mullvadvpn-21c62239a0ef590e77f3a5a3448f36259755d6d8.zip
Remove auto-login
-rw-r--r--app/app.js77
-rw-r--r--app/redux/account/actions.js39
-rw-r--r--app/redux/account/reducers.js1
3 files changed, 57 insertions, 60 deletions
diff --git a/app/app.js b/app/app.js
index 3171d69b76..de60873dae 100644
--- a/app/app.js
+++ b/app/app.js
@@ -3,7 +3,11 @@
import React from 'react';
import { bindActionCreators } from 'redux';
import { Provider } from 'react-redux';
-import { ConnectedRouter, push as pushHistory } from 'connected-react-router';
+import {
+ ConnectedRouter,
+ push as pushHistory,
+ replace as replaceHistory,
+} from 'connected-react-router';
import { createMemoryHistory } from 'history';
import { webFrame, ipcRenderer } from 'electron';
@@ -50,7 +54,13 @@ export default class AppRenderer {
account: bindActionCreators(accountActions, dispatch),
connection: bindActionCreators(connectionActions, dispatch),
settings: bindActionCreators(settingsActions, dispatch),
- history: bindActionCreators({ push: pushHistory }, dispatch),
+ history: bindActionCreators(
+ {
+ push: pushHistory,
+ replace: replaceHistory,
+ },
+ dispatch,
+ ),
};
this._openConnectionObserver = this._daemonRpc.addOpenConnectionObserver(() => {
@@ -110,23 +120,27 @@ export default class AppRenderer {
async login(accountToken: AccountToken) {
const actions = this._reduxActions;
+ const history = this._memoryHistory;
actions.account.startLogin(accountToken);
- log.debug('Attempting to login');
+ log.debug('Logging in');
try {
const accountData = await this._daemonRpc.getAccountData(accountToken);
await this._daemonRpc.setAccount(accountToken);
- actions.account.loginSuccessful(accountData.expiry);
+ actions.account.updateAccountExpiry(accountData.expiry);
+ actions.account.loginSuccessful();
// Redirect the user after some time to allow for
// the 'Login Successful' screen to be visible
setTimeout(async () => {
- actions.history.push('/connect');
+ if (history.location.pathname === '/') {
+ actions.history.replace('/connect');
+ }
try {
- log.debug('Auto-connecting the tunnel...');
+ log.debug('Auto-connecting the tunnel');
await this.connectTunnel();
} catch (error) {
log.error(`Failed to auto-connect the tunnel: ${error.message}`);
@@ -139,33 +153,29 @@ export default class AppRenderer {
}
}
- async _autologin() {
+ async _restoreSession() {
const actions = this._reduxActions;
- actions.account.startLogin();
+ const history = this._memoryHistory;
- log.debug('Attempting to log in automatically');
+ log.debug('Restoring session');
- try {
- const accountToken = await this._daemonRpc.getAccount();
- if (!accountToken) {
- throw new NoAccountError();
- }
+ const accountToken = await this._daemonRpc.getAccount();
- log.debug(`The daemon had an account number stored: ${accountToken}`);
- actions.account.startLogin(accountToken);
+ if (accountToken) {
+ log.debug(`Got account token: ${accountToken}`);
+ actions.account.updateAccountToken(accountToken);
+ actions.account.loginSuccessful();
- const accountData = await this._daemonRpc.getAccountData(accountToken);
- log.debug('The stored account number still exists:', accountData);
-
- actions.account.loginSuccessful(accountData.expiry);
- actions.history.push('/connect');
- } catch (e) {
- log.warn('Unable to autologin,', e.message);
-
- actions.account.autoLoginFailed();
- actions.history.push('/');
+ if (history.location.pathname === '/') {
+ actions.history.replace('/connect');
+ }
+ } else {
+ log.debug('No account set, showing login view.');
+ ipcRenderer.send('show-window');
- throw e;
+ if (history.location.pathname !== '/') {
+ actions.history.replace('/');
+ }
}
}
@@ -179,7 +189,7 @@ export default class AppRenderer {
this._fetchAccountHistory(),
]);
actions.account.loggedOut();
- actions.history.push('/');
+ actions.history.replace('/');
} catch (e) {
log.info('Failed to logout: ', e.message);
}
@@ -383,16 +393,11 @@ export default class AppRenderer {
log.error(`Cannot authenticate: ${error.message}`);
}
- // autologin
+ // attempt to restore the session
try {
- await this._autologin();
+ await this._restoreSession();
} catch (error) {
- if (error instanceof NoAccountError) {
- log.debug('No previously configured account set, showing window');
- ipcRenderer.send('show-window');
- } else {
- log.error(`Failed to autologin: ${error.message}`);
- }
+ log.error(`Failed to restore session: ${error.message}`);
}
// make sure to re-subscribe to state notifications when connection is re-established.
diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js
index 3cc4b83681..ae42d91b6c 100644
--- a/app/redux/account/actions.js
+++ b/app/redux/account/actions.js
@@ -4,23 +4,13 @@ import { Clipboard } from 'reactxp';
import type { AccountToken } from '../../lib/daemon-rpc';
import type { ReduxThunk } from '../store';
-const copyAccountToken = (): ReduxThunk => {
- return (_, getState) => {
- const accountToken = getState().account.accountToken;
- if (accountToken) {
- Clipboard.setText(accountToken);
- }
- };
-};
-
type StartLoginAction = {
type: 'START_LOGIN',
- accountToken?: AccountToken,
+ accountToken: AccountToken,
};
type LoginSuccessfulAction = {
type: 'LOGIN_SUCCESSFUL',
- expiry?: string,
};
type LoginFailedAction = {
@@ -61,24 +51,23 @@ export type AccountAction =
| UpdateAccountHistoryAction
| UpdateAccountExpiryAction;
-function startLogin(accountToken?: AccountToken): StartLoginAction {
+function startLogin(accountToken: AccountToken): StartLoginAction {
return {
type: 'START_LOGIN',
accountToken: accountToken,
};
}
-function loginSuccessful(expiry: string): LoginSuccessfulAction {
+function loginSuccessful(): LoginSuccessfulAction {
return {
type: 'LOGIN_SUCCESSFUL',
- expiry,
};
}
function loginFailed(error: Error): LoginFailedAction {
return {
type: 'LOGIN_FAILED',
- error: error,
+ error,
};
}
@@ -88,10 +77,6 @@ function loggedOut(): LoggedOutAction {
};
}
-function autoLoginFailed(): LoggedOutAction {
- return loggedOut();
-}
-
function resetLoginError(): ResetLoginErrorAction {
return {
type: 'RESET_LOGIN_ERROR',
@@ -101,14 +86,14 @@ function resetLoginError(): ResetLoginErrorAction {
function updateAccountToken(token: AccountToken): UpdateAccountTokenAction {
return {
type: 'UPDATE_ACCOUNT_TOKEN',
- token: token,
+ token,
};
}
function updateAccountHistory(accountHistory: Array<AccountToken>): UpdateAccountHistoryAction {
return {
type: 'UPDATE_ACCOUNT_HISTORY',
- accountHistory: accountHistory,
+ accountHistory,
};
}
@@ -119,15 +104,23 @@ function updateAccountExpiry(expiry: string): UpdateAccountExpiryAction {
};
}
+function copyAccountToken(): ReduxThunk {
+ return (_, getState) => {
+ const accountToken = getState().account.accountToken;
+ if (accountToken) {
+ Clipboard.setText(accountToken);
+ }
+ };
+}
+
export default {
- copyAccountToken,
startLogin,
loginSuccessful,
loginFailed,
loggedOut,
- autoLoginFailed,
resetLoginError,
updateAccountToken,
updateAccountHistory,
updateAccountExpiry,
+ copyAccountToken,
};
diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js
index dbd854a6c0..7263b51166 100644
--- a/app/redux/account/reducers.js
+++ b/app/redux/account/reducers.js
@@ -40,7 +40,6 @@ export default function(
...{
status: 'ok',
error: null,
- expiry: action.expiry,
},
};
case 'LOGIN_FAILED':