mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-30 10:42:34 +05:30
Exmplitly create redirect action for auth instead of if statement in AuthFlow.run
This commit is contained in:
parent
7f6eddf3c7
commit
a1c713236a
@ -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';
|
||||
|
@ -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`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user