【发布时间】:2017-04-23 05:26:46
【问题描述】:
我正在学习使用 AWS lambda、dynamodb、cogito sync 创建无服务器 API 服务器。一切都很顺利,直到我对users 表感到困惑。
所以基本上,我正在尝试制作 twitter 克隆 API。因此,作为用户,我应该能够创建帖子、关注其他用户等。
Cognito Identity 成功处理了 Signup 和 Signin,问题是如何访问 cognito 上的Users 数据?一个用户可以有following 和followers 属性,其中包含其他用户ID。
我目前所做的,在我使用认知身份注册的应用程序上,然后我将再次调用 API 网关以在 dynamodb 上创建 user。所以基本上有两个独立的用户数据。我不确定这是否是正确的方法。
我应该在后端而不是应用程序上拨打cognito 电话吗?我应该为此设置单独的users 表吗?
ionic 上的示例前端代码
$scope.signup = function() {
$ionicLoading.show({
template: 'Registering user...'
});
// this is the factory for signing up
awsCognitoIdentityFactory.signUp($scope.user.email, $scope.user.name, $scope.user.email, $scope.user.password,
function(err, result) {
if (err) {
errorHandler(err);
return false;
}
// creating user on the api
User.create($scope.user).then(function(response) {
console.log(response);
});
// store locally
store.set('user', $scope.user);
$ionicLoading.hide();
$scope.$apply();
$scope.user = {}; //clear register form
$state.go('confirmation');
});
return true;
};
【问题讨论】:
标签: javascript node.js api aws-api-gateway amazon-cognito