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;
};