Cognito SMS code expired with error: ExpiredCodeException: Invalid code provided, please request a code again

Viewed 11

I am trying to confirm SMS code using 'amazon-cognito-identity-js'. Pls see use case 2: https://www.npmjs.com/package/amazon-cognito-identity-js

Cognito setup to send SMS every login.

public async smsCodeConfirmation(username: string, code: string): Promise<any> {
    const userData = {
      Username: username,
      Pool: this.userPool,
    };
    const cognitoUser = new CognitoUser(userData);
    console.log('## code: ', code);
    cognitoUser.confirmRegistration(code, false, (err, result) => {
      if (err) {
        console.log(err.message || JSON.stringify(err));
        console.log('Error: ', err);
        return;
      }
      console.log(`call result: ${result}`);
    });
  }

But when I try to verify SMS I am getting an error:

## code:  521120
Invalid code provided, please request a code again.
Error:  ExpiredCodeException: Invalid code provided, please request a code again.
    at /home/userTest/Code/app-api/node_modules/amazon-cognito-identity-js/lib/Client.js:153:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ExpiredCodeException'
}

And every new SMS is invalid, I am using AWS SNS Sandbox with verified phone. Maybe it will require some configuration for Cognito?

0 Answers
Related