diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/lib/backend.js | 25 | ||||
| -rw-r--r-- | app/redux/account/actions.js | 4 | ||||
| -rw-r--r-- | app/redux/account/reducers.js | 1 |
3 files changed, 7 insertions, 23 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index a58a12a0cd..d36fc36d41 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -182,11 +182,7 @@ export class Backend { autologin() { log.info('Attempting to log in automatically'); - this._store.dispatch(accountActions.loginChange({ - accountNumber: null, - status: 'logging in', - error: null, - })); + this._store.dispatch(accountActions.startLogin()); return this._ipc.getAccount() .then( accountNumber => { @@ -194,34 +190,21 @@ export class Backend { throw new Error('No account set in the backend, failing autologin'); } log.debug('The backend had an account number stored:', accountNumber); - - this._store.dispatch(accountActions.loginChange({ - accountNumber: accountNumber, - status: 'logging in', - error: null, - })); + this._store.dispatch(accountActions.startLogin(accountNumber)); return this._ipc.getAccountData(accountNumber); }) .then( accountData => { log.info('The stored account number still exists', accountData); - this._store.dispatch(accountActions.loginChange({ - status: 'ok', - paidUntil: accountData.paid_until, - error: null, - })); + this._store.dispatch(accountActions.loginSuccessful(accountData.paid_until)); this._store.dispatch(push('/connect')); }) .catch( e => { log.warn('Unable to autologin', e); - this._store.dispatch(accountActions.loginChange({ - status: 'none', - error: new BackendError('INVALID_ACCOUNT'), - })); - + this._store.dispatch(accountActions.loginFailed(new BackendError('INVALID_ACCOUNT'))); this._store.dispatch(push('/')); }); } diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js index 1be1d4c10d..288e06e857 100644 --- a/app/redux/account/actions.js +++ b/app/redux/account/actions.js @@ -5,7 +5,7 @@ import type { AccountReduxState } from './reducers.js'; type StartLoginAction = { type: 'START_LOGIN', - accountNumber: string, + accountNumber?: string, }; type LoginSuccessfulAction = { type: 'LOGIN_SUCCESSFUL', @@ -26,7 +26,7 @@ export type AccountAction = StartLoginAction | LoginFailedAction | LoginChangeAction; -function startLogin(accountNumber: string): StartLoginAction { +function startLogin(accountNumber?: string): StartLoginAction { return { type: 'START_LOGIN', accountNumber: accountNumber, diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js index dedddd35b7..dc2c985285 100644 --- a/app/redux/account/reducers.js +++ b/app/redux/account/reducers.js @@ -38,6 +38,7 @@ export default function(state: AccountReduxState = initialState, action: ReduxAc case 'LOGIN_FAILED': return { ...state, ...{ status: 'failed', + accountNumber: null, error: action.error, }}; } |
