How to use the @aws-amplify/auth.signIn 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 / Auth / SignIn.tsx View on Github external
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);
github yhenni1989 / ReactNativeAuth / src / components / screens / SignInScreen.js View on Github external
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() {
github TreeHacks / root / src / store / auth / actions.ts View on Github external
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()))
  }
}
github josephluck / internote / ui / auth / auth.ts View on Github external
async function signIn(email: string) {
    user = await Auth.signIn(email);
  }
github awslabs / aws-full-stack-template / assets / src / modules / signup / Login.tsx View on Github external
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 });
      }
    }
  }
github systemaccounting / mxfactorial / react / src / lib / amplify.js View on Github external
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)
    }
  })
}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / SignIn.jsx View on Github external
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');
github awslabs / aws-full-stack-template / assets / src / modules / signup / Signup.tsx View on Github external
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 });
    }
  }