31 lines
912 B
TypeScript
Raw Normal View History

2016-11-13 16:47:56 +02:00
import AbstractState from './AbstractState';
import { AuthContext } from './AuthFlow';
2016-11-13 16:47:56 +02:00
import LoginState from './LoginState';
import CompleteState from './CompleteState';
export default class ChooseAccountState extends AbstractState {
2020-05-24 02:08:24 +03:00
enter(context: AuthContext): Promise<void> | void {
const { auth } = context.getState();
2020-05-24 02:08:24 +03:00
if (auth.oauth) {
context.navigate('/oauth/choose-account');
} else {
context.navigate('/choose-account');
}
2016-11-13 16:47:56 +02:00
}
2020-05-24 02:08:24 +03:00
resolve(context: AuthContext, payload: Record<string, any>): Promise<void> | void {
if (payload.id) {
context.setState(new CompleteState());
} else {
context.navigate('/login');
context.run('setLogin', null);
context.setState(new LoginState());
}
2016-11-13 16:47:56 +02:00
}
2020-05-24 02:08:24 +03:00
reject(context: AuthContext): void {
context.run('logout');
}
2016-11-13 16:47:56 +02:00
}