[英]AWS AmplifyAUTH: flutter: [ERROR]: CreateAuthChallenge failed with error SyntaxError: await is only valid in async function
Getting the captioned error message onTap signUpButton() within AuthenticatorForm().在 AuthenticatorForm() 中获取带标题的错误消息 onTap signUpButton()。 Seems like a very idiomatic error message, but can't seem to find what's wrong.
似乎是一个非常惯用的错误消息,但似乎无法找到问题所在。
Here is my createAuthChallenge.js这是我的 createAuthChallenge.js
const AWS = require('aws-sdk');
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和我的 package.json 同样
{
"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?我似乎找不到合适的解决方案,有人可以帮忙吗?
Please try to replace your last line with:请尝试将您的最后一行替换为:
exports.handler = createAuthChallenge;
If it doesn't work, can you add some other details?如果它不起作用,你可以添加一些其他细节吗?
Not really a useful answer, but as self-resolved.这不是一个真正有用的答案,而是自我解决的。
Ultimately just used the same codes that I copied above, but redid everything from amplify delete > amplify init > amplify add auth > amplify push.最终只是使用了我在上面复制的相同代码,但重新做了从放大删除 > 放大初始化 > 放大添加身份验证 > 放大推送的所有内容。 After this, no errors in simulator.
在此之后,模拟器中没有错误。
If anyone runs into similar problems, the best approach based off my experience on this, is to check the cloudwatch logs of the lambdas fired.如果有人遇到类似问题,根据我的经验,最好的方法是检查被触发的 lambda 的 cloudwatch 日志。 In most cases, the logs should do a better job of pointing out where the issue is than the error messages in local.
在大多数情况下,日志应该比本地的错误消息更好地指出问题所在。 If that doesn't work, backup everything and reset amplify.
如果这不起作用,请备份所有内容并重置放大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.