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

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南