Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async signIn(event) {
// avoid submitting the form
if (event) {
event.preventDefault();
}
const username = this.getUsernameFromInput() || '';
const password = this.inputs.password;
if (!Auth || typeof Auth.signIn !== 'function') {
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
}
this.setState({loading: true});
try {
const user = await Auth.signIn(username, password);
logger.debug(user);
if (user.challengeName === 'SMS_MFA' || user.challengeName === 'SOFTWARE_TOKEN_MFA') {
logger.debug('confirm user with ' + user.challengeName);
this.changeState('confirmSignIn', user);
} else if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
logger.debug('require new password', user.challengeParam);
this.changeState('requireNewPassword', user);
} else if (user.challengeName === 'MFA_SETUP') {
logger.debug('TOTP setup', user.challengeParam);
this.changeState('TOTPSetup', user);
} else if (user.challengeName === 'CUSTOM_CHALLENGE' &&
user.challengeParam &&
user.challengeParam.trigger === 'true'
) {
logger.debug('custom challenge', user.challengeParam);
this.changeState('customConfirmSignIn', user);
async signIn() {
const { username, password } = this.state
await Auth.signIn(username, password)
.then(user => {
this.setState({ user })
this.props.navigation.navigate('Authloading')
})
.catch(err => {
if (! err.message) {
console.log('Error when signing in: ', err)
Alert.alert('Error when signing in: ', err)
} else {
console.log('Error when signing in: ', err.message)
Alert.alert('Error when signing in: ', err.message)
}
})
}
render() {
return dispatch => {
let email = data.email.toLowerCase().trim();
dispatch(loadingStart());
dispatch(setAttemptedLoginEmail(email));
Auth.signIn(email, data.password)
.then(user => {
if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
dispatch(setUser(user));
dispatch(setAuthPage("changePassword", "Welcome to TreeHacks. To finish logging in, please set a new password for your account."));
} else {
dispatch(checkLoginStatus());
}
})
.catch(e => dispatch(onAuthError(e.message)))
.then(() => dispatch(loadingEnd()))
}
}
async function signIn(email: string) {
user = await Auth.signIn(email);
}
onLogin = async (event: React.FormEvent) => {
if (event.currentTarget.checkValidity()) {
event.preventDefault();
event.stopPropagation();
this.setState({ isValid: true, loading: true });
try {
await Auth.signIn(this.state.email, this.state.password);
this.props.userHasAuthenticated(true);
this.setState({ redirect: true })
} catch (e) {
alert(e.message);
this.setState({ loading: false });
}
}
}
export const signIn = ({ account, password }) => {
return Auth.signIn(account, password).then(async token => {
if (token) {
const user = await Auth.currentUserInfo()
localStorage.setItem('credential', cryptString(password))
singInPerform.next(user)
}
})
}
async signIn() {
const { username, password } = this.inputs;
if (!Auth || typeof Auth.signIn !== 'function') {
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
}
this.setState({loading: true});
try {
const user = await Auth.signIn(username, password);
logger.debug(user);
if (user.challengeName === 'SMS_MFA' || user.challengeName === 'SOFTWARE_TOKEN_MFA') {
logger.debug('confirm user with ' + user.challengeName);
this.changeState('confirmSignIn', user);
} else if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
logger.debug('require new password', user.challengeParam);
this.changeState('requireNewPassword', user);
} else if (user.challengeName === 'MFA_SETUP') {
logger.debug('TOTP setup', user.challengeParam);
this.changeState('TOTPSetup', user);
} else {
this.checkContact(user);
}
} catch (err) {
if (err.code === 'UserNotConfirmedException') {
logger.debug('the user is not confirmed');
onConfirm = async (event: React.FormEvent) => {
event.preventDefault();
this.setState({ loading: true });
try {
await Auth.confirmSignUp(this.state.email, this.state.confirmationCode);
await Auth.signIn(this.state.email, this.state.password);
this.props.userHasAuthenticated(true);
this.setState({ redirect: true })
} catch (e) {
alert(e.message);
this.setState({ loading: false });
}
}