diff --git a/src/components/auth/actions.js b/src/components/auth/actions.js index 427f442..41dd32a 100644 --- a/src/components/auth/actions.js +++ b/src/components/auth/actions.js @@ -1,6 +1,7 @@ import { routeActions } from 'react-router-redux'; import logger from 'services/logger'; +import loader from 'services/loader'; import history from 'services/history'; import { updateUser, acceptRules as userAcceptRules } from 'components/user/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}) { const PASSWORD_REQUIRED = 'error.password_required'; const LOGIN_REQUIRED = 'error.login_required'; diff --git a/src/services/authFlow/AuthFlow.js b/src/services/authFlow/AuthFlow.js index 102b1d5..f2dabf8 100644 --- a/src/services/authFlow/AuthFlow.js +++ b/src/services/authFlow/AuthFlow.js @@ -1,7 +1,6 @@ import { routeActions } from 'react-router-redux'; import logger from 'services/logger'; -import loader from 'services/loader'; import RegisterState from './RegisterState'; import LoginState from './LoginState'; @@ -63,16 +62,6 @@ export default class AuthFlow { } 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]) { throw new Error(`Action ${actionId} does not exists`); }