How to use the @aws-amplify/auth.setupTOTP 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.jsx View on Github external
setup() {
        this.setState({setupMessage: null});
        const user = this.props.authData;
        if (!Auth || typeof Auth.setupTOTP !== 'function') {
            throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
        }

        Auth.setupTOTP(user).then((data) => {
            logger.debug('secret key', data);
            const code = "otpauth://totp/AWSCognito:"+ user.username + "?secret=" + data + "&issuer=AWSCognito";
            this.setState({code});
        }).catch((err) => logger.debug('totp setup failed', err));
    }
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Widget / TOTPSetupComp.tsx View on Github external
setup() {
		this.setState({ setupMessage: null });
		const user = this.props.authData;
		const issuer = encodeURI(I18n.get('AWSCognito'));
		if (!Auth || typeof Auth.setupTOTP !== 'function') {
			throw new Error(
				'No Auth module found, please ensure @aws-amplify/auth is imported'
			);
		}

		Auth.setupTOTP(user)
			.then(data => {
				logger.debug('secret key', data);
				const code =
					'otpauth://totp/' +
					issuer +
					':' +
					user.username +
					'?secret=' +
					data +
					'&issuer=' +
					issuer;
				this.setState({ code });
			})
			.catch(err => logger.debug('totp setup failed', err));
	}