creating user using AWS cognito identity

强颜欢笑 提交于 2020-01-07 05:41:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!