我正在使用 AWS 为 WebApp 工作。我正在尝试从我的 DynamoDB 表中获取项目,但我收到错误“此身份池不支持未经身份验证的访问”。我不希望我的应用程序拥有未经身份验证的用户,但我在调用 DynamoDB 查询之前已登录。谁能帮我?这是我的代码:
function facebookLogin () {
FB.login(function (response) {
if (response.authResponse) { // logged in
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'myActualPoolId'
});
AWS.config.region = 'us-east-1';
AWS.config.credentials.params.logins = {}
AWS.config.credentials.params.logins['graph.facebook.com'] = response.authResponse.accessToken;
AWS.config.credentials.expired = true;
console.log("Importing drivers into DynamoDB. Please wait.");
var drivers = JSON.parse('[{"userId": "4","driverId": "4d","ratingValue": 3,"truckId": "4"},{"userId": "5","driverId": "5d","ratingValue": 2,"truckId": "5"}]');
drivers.forEach(function(driver) {
var params = {
TableName: "myActualTableName",
Item: {
"userId": driver.year,
"driverId": driver.title,
"ratingValue": driver.info,
"truckId": driver.truckId
}
};
var docClient = new AWS.DynamoDB.DocumentClient();
docClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add driver", driver.userId, ". Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("PutItem succeeded:", driver.userId);
}
});
});
} else {
console.log('There was a problem logging you in.');
}
});
}
我将不胜感激任何帮助。谢谢!