How to use the @aws-amplify/auth.setPreferredMFA function in @aws-amplify/auth

To help you get started, we’ve selected a few @aws-amplify/auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-js / packages / aws-amplify-react / src / Widget / TOTPSetupComp.tsx View on Github external
.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 => {
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Widget / TOTPSetupComp.jsx View on Github external
.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 => {
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Widget / SelectMFAType.jsx View on Github external
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
                });
            }