问题
I am learning to create a serverless API server using AWS lambda, dynamodb, cogito sync. It was going well until I got confused with users
table.
So basically, I am trying to make twitter clone API. So as user I should be able to create post, follow another users etc.
Signup and Signin are successfully handled by Cognito Identity, the problem is how do I access the Users
data on the cognito? A user can have following
and followers
attributes which contains other users ID.
What I did currently, on the app I register using cognito identity then I will make another call to the API gateway to create a user
on dynamodb. So basically there are two separate users data. I am not sure if this is the correct way to do this.
Should I make a call on cognito
on the backend instead on the app? Should i have separate users
table for this?
Example Front End code on 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;
};
回答1:
It sounds like you're using Cognito User Pools, in which case you can use the GetUser API. Given context for the user, it will return all attributes stored against that user.
I can't comment on the best way to store user metadata as it will vary greatly based on the specifics and needs of your app, but it's probably worth reading up on Cognito's system of custom attributes, which lets you store custom data against users. These can be configured/added from the Cognito console.
来源:https://stackoverflow.com/questions/41031529/creating-user-using-aws-cognito-identity