Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
// set it to preferred mfa
Auth.setPreferredMFA(user, 'TOTP');
this.setState({ setupMessage: 'Setup TOTP successfully!' });
logger.debug('set up totp success!');
this.triggerTOTPEvent('Setup TOTP', 'SUCCESS', user);
})
.catch(err => {
.then(() => {
// set it to preferred mfa
Auth.setPreferredMFA(user, 'TOTP');
this.setState({setupMessage: 'Setup TOTP successfully!'});
logger.debug('set up totp success!');
this.triggerTOTPEvent('Setup TOTP', 'SUCCESS', user);
})
.catch(err => {
let mfaMethod = null;
if (TOTP) {
mfaMethod = 'TOTP';
} else if (SMS) {
mfaMethod = 'SMS';
} else if (NOMFA) {
mfaMethod = 'NOMFA';
}
const user = this.props.authData;
if (!Auth || typeof Auth.setPreferredMFA !== 'function') {
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
}
Auth.setPreferredMFA(user, mfaMethod).then((data) => {
logger.debug('set preferred mfa success', data);
this.setState({
selectMessage: 'Success! Your MFA Type is now: ' + mfaMethod,
showToast: true
});
}).catch(err => {
const { message } = err;
if (message === 'User has not set up software token mfa'
|| message === 'User has not verified software token mfa') {
this.setState({
TOTPSetup: true,
selectMessage: 'You need to setup TOTP',
showToast: true
});
}