diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js
index 6b74c6234..83cb82aea 100644
--- a/app/soapbox/actions/auth.js
+++ b/app/soapbox/actions/auth.js
@@ -191,7 +191,7 @@ export function logOut() {
};
}
-export function switchAccount(accountId) {
+export function switchAccount(accountId,) {
return { type: SWITCH_ACCOUNT, accountId };
}
diff --git a/app/soapbox/features/auth_login/components/login_page.js b/app/soapbox/features/auth_login/components/login_page.js
index 30e0cc94b..1ebdc8dda 100644
--- a/app/soapbox/features/auth_login/components/login_page.js
+++ b/app/soapbox/features/auth_login/components/login_page.js
@@ -1,10 +1,9 @@
import React from 'react';
import { connect } from 'react-redux';
-import { Redirect } from 'react-router-dom';
import ImmutablePureComponent from 'react-immutable-pure-component';
import LoginForm from './login_form';
import OtpAuthForm from './otp_auth_form';
-import { logIn, verifyCredentials } from 'soapbox/actions/auth';
+import { logIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth';
const mapStateToProps = state => ({
me: state.get('me'),
@@ -32,10 +31,14 @@ class LoginPage extends ImmutablePureComponent {
}
handleSubmit = (event) => {
- const { dispatch } = this.props;
+ const { dispatch, me } = this.props;
const { username, password } = this.getFormData(event.target);
dispatch(logIn(username, password)).then(({ access_token }) => {
return dispatch(verifyCredentials(access_token));
+ }).then(account => {
+ if (typeof me === 'string') {
+ dispatch(switchAccount(account.id));
+ }
}).catch(error => {
if (error.response.data.error === 'mfa_required') {
this.setState({ mfa_auth_needed: true, mfa_token: error.response.data.mfa_token });
@@ -47,9 +50,7 @@ class LoginPage extends ImmutablePureComponent {
}
render() {
- const { me } = this.props;
const { isLoading, mfa_auth_needed, mfa_token } = this.state;
- if (me) return ;
if (mfa_auth_needed) return ;
diff --git a/app/soapbox/reducers/auth.js b/app/soapbox/reducers/auth.js
index 1a9a72c82..d44767f87 100644
--- a/app/soapbox/reducers/auth.js
+++ b/app/soapbox/reducers/auth.js
@@ -117,15 +117,15 @@ const reducer = (state, action) => {
};
const maybeReload = (oldState, state, action) => {
- const conds = [
- action.type === SWITCH_ACCOUNT,
- action.type === VERIFY_CREDENTIALS_FAIL && state.get('me') !== oldState.get('me'),
- ];
+ if (action.type === SWITCH_ACCOUNT) {
+ if (location.pathname === '/auth/sign_in') {
+ location.replace('/');
+ } else {
+ location.reload();
+ }
+ }
- // Reload if any of these conditions are true
- const shouldReload = conds.some(cond => cond);
-
- if (shouldReload) {
+ if (action.type === VERIFY_CREDENTIALS_FAIL && state.get('me') !== oldState.get('me')) {
location.reload();
}
};