mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-26 15:00:23 +05:30
8075192472
Improve auth's ChooseAccount visual behavior Rework the ComponentLoader component. Make it more stylable
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import logger from 'app/services/logger';
|
|
|
|
import { getCredentials } from 'app/components/auth/reducer';
|
|
|
|
import AbstractState from './AbstractState';
|
|
import CompleteState from './CompleteState';
|
|
import PasswordState from './PasswordState';
|
|
import { AuthContext } from './AuthFlow';
|
|
|
|
export default class MfaState extends AbstractState {
|
|
enter(context: AuthContext): Promise<void> | void {
|
|
const { login, password, isTotpRequired } = getCredentials(context.getState());
|
|
|
|
if (login && password && isTotpRequired) {
|
|
context.navigate('/mfa');
|
|
} else {
|
|
context.setState(new CompleteState());
|
|
}
|
|
}
|
|
|
|
resolve(context: AuthContext, { totp }: { totp: string }): Promise<void> | void {
|
|
const { login, password, rememberMe, isRelogin } = getCredentials(context.getState());
|
|
|
|
return context
|
|
.run('login', {
|
|
login,
|
|
password,
|
|
totp,
|
|
rememberMe,
|
|
})
|
|
.then(() => !isRelogin && context.run('setAccountSwitcher', false))
|
|
.then(() => context.setState(new CompleteState()))
|
|
.catch((err = {}) => err.errors || logger.warn('Error logging in', err));
|
|
}
|
|
|
|
goBack(context: AuthContext) {
|
|
context.setState(new PasswordState());
|
|
}
|
|
}
|