Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
Uncaught (in promise) TypeError: callback is undefined amazon-cognito-identity-js user.completeNewPasswordChallenge

all. Can anyone help me understand why I am getting a Uncaught (in promise) TypeError: callback is undefined in the below code? It does not make it to the on success or on failure clauses.

const onSubmitPasscode = (event) => {
    event.preventDefault();

    if (passwordFirst !== passwordSecond) {
      alert('the two inputs provided are not the same');
    } else {
      const user = new CognitoUser({
        Username: email,
        Pool: UserPool
      });

      const authDetails = new AuthenticationDetails({
        Username: email,
        Password: password
      });

      user.authenticateUser(authDetails, {
        onFailure: (err) => {
          console.error('onFailure:', err);
        },
        newPasswordRequired: () => {
          user.completeNewPasswordChallenge(passwordFirst, {
            onFailure: (err) => {
              console.error('onFailure:', err);
            },
            onSuccess: (result) => {
              console.log(passwordFirst);
              console.log('call result: ', result);
              navigate('dashboard');
            }
          });
        }
      });
    }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Define an onSuccess function for authenticateUser:

user.authenticateUser(authDetails, {
  onSuccess: (result) => {
    console.log(result);
  },
  onFailure: (err) => {
    console.error('onFailure:', err);
  },
  newPasswordRequired: () => {
    user.completeNewPasswordChallenge(passwordFirst, {
      onFailure: (err) => {
        console.error('onFailure:', err);
      },
      onSuccess: (result) => {
        console.log(passwordFirst);
        console.log('call result: ', result);
        navigate('dashboard');
      }
    });
  }
}

Also, based on the documentation, newPasswordRequired takes a function whose signature is different from what you are providing. So I think what you might want is really:

user.authenticateUser(authDetails, {
  onSuccess: (result) => {
    console.log(passwordFirst);
    console.log('call result: ', result);
    navigate('dashboard');
  }
  onFailure: (err) => {
    console.error('onFailure:', err);
  },
  newPasswordRequired: (userAttributes, requiredAttributes) => {
    /*whatever you want to do when new password is required*/
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Upon reading the documentation further, the userAttributes.email_verified is not allowed to be returned and must be deleted. I did this. However - my application was still not working because the API does not accept the phone_number_verified either in the return call. I have these two lines now:

const onSubmit = (event) => { // first log in attempt with the temporary passcode OR with permanent changed passcode
    event.preventDefault();

    const authDetails = new AuthenticationDetails({
      Username: email,
      Password: password
    });

    const user = new CognitoUser({
      Username: email,
      Pool: UserPool
    });

    user.authenticateUser(authDetails, {
      onSuccess: (data) => {
        console.log('onSuccess:', data);
        if (location.pathname === '/') {
          navigate('dashboard');
        }
      },
      onFailure: (err) => {
        console.error('onFailure:', err);
      },
      newPasswordRequired: (data) => {
        setNewPasscodeRequired(true); // once this is set to true, my application shows a new component which requests the password twice and tells the user the rules for the passcode
      }
    });
  };

  const onSubmitPasscode = (event) => { // once they submit their new passcode
    event.preventDefault();

    if (passwordFirst !== passwordSecond) {
      alert('the two inputs provided are not the same');
    } else {
      const user = new CognitoUser({
        Username: email,
        Pool: UserPool
      });

      const authDetails = new AuthenticationDetails({
        Username: email,
        Password: password
      });

      user.authenticateUser(authDetails, {
        onFailure: (err) => {
          console.error('onFailure:', err);
        },
        onSuccess: (result) => {
          console.log(result);
        },
        newPasswordRequired: (userAttributes, requiredAttributes) => {
          delete userAttributes.email_verified; // THIS IS NON NEGOTIABLE
          delete userAttributes.phone_number_verified; // THIS IS NON NEGOTIABLE
          user.completeNewPasswordChallenge(passwordFirst, userAttributes, {
            onFailure: (err) => {
              console.error('onFailure:', err);
            },
            onSuccess: (result) => {
              console.log('call result: ', result);
              navigate('dashboard');
            }
          });
        }
      });
    }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda