accounts-frontend/src/services/authFlow/LoginState.js

24 lines
806 B
JavaScript
Raw Normal View History

2016-03-02 02:06:14 +05:30
import AbstractState from './AbstractState';
import PasswordState from './PasswordState';
export default class LoginState extends AbstractState {
enter(context) {
const {auth, user} = context.getState();
2016-03-02 02:06:14 +05:30
// TODO: it may not allow user to leave password state till he click back or enters password
if (auth.login) {
2016-03-02 02:06:14 +05:30
context.setState(new PasswordState());
} else if (user.isGuest
// for the case, when user is logged in and wants to add a new aacount
|| /login|password/.test(context.getRequest().path) // TODO: improve me
) {
2016-03-02 02:06:14 +05:30
context.navigate('/login');
}
}
resolve(context, payload) {
context.run('login', payload)
.then(() => context.setState(new PasswordState()));
}
}