flutter: [ERROR]: CreateAuthChallenge failed with error SyntaxError: await is only valid in async function

0

Getting the captioned error message onTap signUpButton() within AuthenticatorForm(). Seems like a very straightforward error message, but can't seem to identify what's wrong.

Here is my createAuthChallenge.js

const digitGenerator = require('crypto-secure-random-digit');

function sendSMS(phone, code) {
  const params = {
    Message: code,
    PhoneNumber: phone,
  };
  return new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise();
}

async function createAuthChallenge(event) {
  if (event.request.challengeName === 'CUSTOM_CHALLENGE') {
    const randomDigits = digitGenerator.randomDigits(6).join('');
    const challengeCode = String(randomDigits).join('');
    await sendSMS(event.request.userAttributes.phone_number, challengeCode);
  
    event.response.privateChallengeParameters = {};
    event.response.privateChallengeParameters.answer = challengeCode;
  }
}

exports.handler = async (event) => {
  createAuthChallenge(event);
};

And my package.json for the same

{
  "name": "XYZ",
  "version": "2.0.0",
  "description": "Lambda function generated by Amplify",
  "main": "index.js",
  "license": "Apache-2.0",
  "devDependencies": {
    "@types/aws-lambda": "^8.10.92"
  },
  "dependencies": {
    "crypto-secure-random-digit": "^1.0.9"
  }
}

I can't seem to find the right solution for this, can anyone help please?

  • I am a bit puzzled since the error message seems to be be generated by the Flutter code and not the lambda function. Can you possibly provide the CloudWatch Logs of the lambda function?

  • Thanks for the comment, I did just the same, and the issue seemed to have been with UserFunctions.js. As the logs were not really helpful beyond that, I deleted amplify and copied the same lambdas, and now seems to work.

1개 답변
0
수락된 답변

Not entirely sure what the root cause of the error messages above were, but there is nothing wrong with the codes above. Redid everything from amplify delete > amplify init > amplify add auth > add lambdas to local > amplify push And now everything works, most likely some odd mistake that I made without realizing

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠