Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value: function verifyTotpToken() {
var _this3 = this;
if (!this.inputs) {
logger.debug('no input');
return;
}
var user = this.props.authData;
var totpCode = this.inputs.totpCode;
_awsAmplify.Auth.verifyTotpToken(user, totpCode).then(function () {
// set it to preferred mfa
_awsAmplify.Auth.setPreferredMFA(user, 'TOTP');
_this3.setState({ setupMessage: 'Setup TOTP successfully!' });
logger.debug('set up totp success!');
_this3.triggerTOTPEvent('Setup TOTP', 'SUCCESS', user);
}).catch(function (err) {
_this3.setState({ setupMessage: 'Setup TOTP failed!' });
logger.error(err);
});
}
}, {
value: function checkContact(user) {
var _this2 = this;
_awsAmplify.Auth.verifiedContact(user).then(function (data) {
if (!_awsAmplify.JS.isEmpty(data.verified)) {
_this2.changeState('signedIn', user);
} else {
user = Object.assign(user, data);
_this2.changeState('verifyContact', user);
}
});
}
}, {
function setup() {
var _this2 = this;
var user = this.props.authData;
_awsAmplify.Auth.setupTOTP(user).then(function (data) {
logger.debug('secret key', data);
var code = "otpauth://totp/AWSCognito:" + user.username + "?secret=" + data + "&issuer=AWSCognito";
_this2.setState({ code: code });
})['catch'](function (err) {
return logger.debug('mfa setup failed', err);
});
}
value: function signUp() {
var _this2 = this;
var _inputs = this.inputs,
username = _inputs.username,
password = _inputs.password,
email = _inputs.email,
phone_number = _inputs.phone_number;
_awsAmplify.Auth.signUp(username, password, email, phone_number).then(function () {
return _this2.changeState('confirmSignUp', username);
}).catch(function (err) {
return _this2.error(err);
});
}
}, {
value: function change() {
var _this3 = this;
var user = this.props.authData;
var password = this.inputs.password;
var requiredAttributes = user.challengeParam.requiredAttributes;
_awsAmplify.Auth.completeNewPassword(user, password, requiredAttributes).then(function (user) {
logger.debug('complete new password', user);
if (user.challengeName === 'SMS_MFA') {
_this3.changeState('confirmSignIn', user);
} else if (user.challengeName === 'MFA_SETUP') {
logger.debug('TOTP setup', user.challengeParam);
_this3.changeState('TOTPSetup', user);
} else {
_this3.checkContact(user);
}
}).catch(function (err) {
return _this3.error(err);
});
}
}, {
function setup() {
var _this2 = this;
this.setState({ setupMessage: null });
var user = this.props.authData;
_awsAmplify.Auth.setupTOTP(user).then(function (data) {
logger.debug('secret key', data);
var code = "otpauth://totp/AWSCognito:" + user.username + "?secret=" + data + "&issuer=AWSCognito";
_this2.setState({ code: code });
})['catch'](function (err) {
return logger.debug('mfa setup failed', err);
});
}
value: function confirm() {
var _this3 = this;
var user = this.props.authData;
var code = this.inputs.code;
var mfaType = user.challengeName === 'SOFTWARE_TOKEN_MFA' ? 'SOFTWARE_TOKEN_MFA' : null;
_awsAmplify.Auth.confirmSignIn(user, code, mfaType).then(function () {
_this3.checkContact(user);
}).catch(function (err) {
return _this3.error(err);
});
}
}, {
value: function checkContact(user) {
var _this2 = this;
_awsAmplify.Auth.verifiedContact(user).then(function (data) {
if (!_awsAmplify.JS.isEmpty(data.verified)) {
_this2.changeState('signedIn', user);
} else {
user = Object.assign(user, data);
_this2.changeState('verifyContact', user);
}
});
}
}, {
fb.api('/me', function (response) {
var user = {
name: response.name
};
_awsAmplify.Auth.federatedSignIn('facebook', { token: accessToken, expires_at: expires_at }, user).then(function (credentials) {
if (onStateChange) {
onStateChange('signedIn');
}
});
});
}