From a1c713236a09428b9f2ededabd0e58b410efb95c Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Wed, 1 Feb 2017 08:22:12 +0200 Subject: [PATCH] Exmplitly create redirect action for auth instead of if statement in AuthFlow.run --- src/components/auth/actions.js | 11 +++++++++++ src/services/authFlow/AuthFlow.js | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) 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`); }