Exmplitly create redirect action for auth instead of if statement in AuthFlow.run

This commit is contained in:
SleepWalker 2017-02-01 08:22:12 +02:00
parent 7f6eddf3c7
commit a1c713236a
2 changed files with 11 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import { routeActions } from 'react-router-redux'; import { routeActions } from 'react-router-redux';
import logger from 'services/logger'; import logger from 'services/logger';
import loader from 'services/loader';
import history from 'services/history'; import history from 'services/history';
import { updateUser, acceptRules as userAcceptRules } from 'components/user/actions'; import { updateUser, acceptRules as userAcceptRules } from 'components/user/actions';
import { authenticate, logoutAll } from 'components/accounts/actions'; import { authenticate, logoutAll } from 'components/accounts/actions';
@ -31,6 +32,16 @@ export function goBack(fallbackUrl = null) {
}; };
} }
export function redirect(url) {
loader.show();
return () => new Promise(() => {
// do not resolve promise to make loader visible and
// overcome app rendering
location.href = url;
});
}
export function login({login = '', password = '', rememberMe = false}) { export function login({login = '', password = '', rememberMe = false}) {
const PASSWORD_REQUIRED = 'error.password_required'; const PASSWORD_REQUIRED = 'error.password_required';
const LOGIN_REQUIRED = 'error.login_required'; const LOGIN_REQUIRED = 'error.login_required';

View File

@ -1,7 +1,6 @@
import { routeActions } from 'react-router-redux'; import { routeActions } from 'react-router-redux';
import logger from 'services/logger'; import logger from 'services/logger';
import loader from 'services/loader';
import RegisterState from './RegisterState'; import RegisterState from './RegisterState';
import LoginState from './LoginState'; import LoginState from './LoginState';
@ -63,16 +62,6 @@ export default class AuthFlow {
} }
run(actionId, payload) { run(actionId, payload) {
if (actionId === 'redirect') {
loader.show();
return new Promise(() => {
// do not resolve promise to make loader visible and
// overcome app rendering
location.href = payload;
});
}
if (!this.actions[actionId]) { if (!this.actions[actionId]) {
throw new Error(`Action ${actionId} does not exists`); throw new Error(`Action ${actionId} does not exists`);
} }