mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-10 10:02:02 +05:30
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
|
// @flow
|
||
|
import logger from 'services/logger';
|
||
|
|
||
|
import { getCredentials } from 'components/auth/reducer';
|
||
|
|
||
|
import AbstractState from './AbstractState';
|
||
|
import CompleteState from './CompleteState';
|
||
|
import PasswordState from './PasswordState';
|
||
|
|
||
|
import type { AuthContext } from './AuthFlow';
|
||
|
|
||
|
export default class MfaState extends AbstractState {
|
||
|
enter(context: AuthContext) {
|
||
|
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}) {
|
||
|
const {
|
||
|
login,
|
||
|
password,
|
||
|
rememberMe
|
||
|
} = getCredentials(context.getState());
|
||
|
|
||
|
context.run('login', {
|
||
|
totp,
|
||
|
password,
|
||
|
rememberMe,
|
||
|
login
|
||
|
})
|
||
|
.then(() => context.setState(new CompleteState()))
|
||
|
.catch((err = {}) =>
|
||
|
err.errors || logger.warn('Error logging in', err)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
goBack(context: AuthContext) {
|
||
|
context.setState(new PasswordState());
|
||
|
}
|
||
|
}
|