2020-10-11 22:45:53 +05:30
|
|
|
import type { Account } from 'app/components/accounts/reducer';
|
|
|
|
|
2016-11-13 20:17:56 +05:30
|
|
|
import AbstractState from './AbstractState';
|
2020-01-18 02:07:52 +05:30
|
|
|
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();
|
2018-02-18 01:29:35 +05:30
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
// This method might be called with an empty object to mention that user wants to login into a new account.
|
|
|
|
// Currently, I can't correctly provide typing since there is no type for an empty object.
|
|
|
|
// So if there is no `id` property, it's an empty object
|
|
|
|
resolve(context: AuthContext, payload: Account): Promise<void> | void {
|
2020-05-24 04:38:24 +05:30
|
|
|
if (payload.id) {
|
2020-10-23 03:53:59 +05:30
|
|
|
return context
|
|
|
|
.run('authenticate', payload)
|
|
|
|
.then(() => context.run('setAccountSwitcher', false))
|
|
|
|
.then(() => context.setState(new CompleteState()));
|
2020-05-24 04:38:24 +05:30
|
|
|
}
|
2020-10-23 03:53:59 +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
|
|
|
}
|
2016-11-19 17:49:23 +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
|
|
|
}
|