How to use the @aws-amplify/auth.Auth.completeNewPassword 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 / amplify-ui-components / src / components / amplify-require-new-password / amplify-require-new-password.tsx View on Github external
async completeNewPassword(event) {
    if (event) {
      event.preventDefault();
    }

    if (!Auth || typeof Auth.completeNewPassword !== 'function') {
      throw new Error(NO_AUTH_MODULE_FOUND);
    }

    try {
      const { requiredAttributes } = this.user.challengeParam;
      const user = await Auth.completeNewPassword(this.user, this.password, requiredAttributes);
      user.challengeParameter;

      logger.debug('complete new password', user);
      switch (user.challengeName) {
        case ChallengeName.SMSMFA:
          this.handleAuthStateChange(AuthState.ConfirmSignIn, user);
          break;
        case ChallengeName.MFASetup:
          logger.debug('TOTP setup', user.challengeParam);
          this.handleAuthStateChange(AuthState.TOTPSetup, user);
          break;
        default:
          this.checkContact(user);
      }
    } catch (error) {
      logger.error(error);