accounts-frontend/packages/app/services/authFlow/ChooseAccountState.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { Account } from 'app/components/accounts/reducer';
2016-11-13 20:17:56 +05:30
import AbstractState from './AbstractState';
import { AuthContext } from './AuthFlow';
2016-11-13 20:17:56 +05:30
import LoginState from './LoginState';
import CompleteState from './CompleteState';
export default class ChooseAccountState extends AbstractState {
2020-05-24 04:38:24 +05:30
enter(context: AuthContext): Promise<void> | void {
const { auth } = context.getState();
2020-05-24 04:38:24 +05:30
if (auth.oauth) {
context.navigate('/oauth/choose-account');
} else {
context.navigate('/choose-account');
}
2016-11-13 20:17:56 +05:30
}
resolve(context: AuthContext, payload: Account | Record<string, any>): Promise<void> | void {
2020-05-24 04:38:24 +05:30
if (payload.id) {
// payload is Account
return context
.run('authenticate', payload)
.then(() => context.run('setAccountSwitcher', false))
.then(() => context.setState(new CompleteState()));
2020-05-24 04:38:24 +05:30
}
// log in to another account
context.navigate('/login');
context.run('setLogin', null);
context.setState(new LoginState());
2016-11-13 20:17:56 +05:30
}
2020-05-24 04:38:24 +05:30
reject(context: AuthContext): void {
context.run('logout');
}
2016-11-13 20:17:56 +05:30
}