【问题标题】:How to search users in Cognito userpool in React Native app如何在 React Native 应用程序的 Cognito 用户池中搜索用户
【发布时间】:2021-05-20 23:36:35
【问题描述】:

我正在使用 React Native 和 Amplify(包括身份验证)构建一个应用,需要让用户搜索和关注其他也在使用该应用的用户。

身份验证流程运行良好,但我无法在 cognito 用户池中搜索用户列表。

根据 amplify-js/packages/amazon-cognito-identity-js/,其中一个 v1.0 功能启用了“使用用户属性搜索池中的用户。”,但到目前为止我找不到任何其他文档或示例。

我尝试使用 aws-amplify 模块中的 Auth 对象和 amazon-cognito-identity-js 模块中的 CognitoUserPool 对象,但似乎都没有提供搜索功能。

我该怎么办?

【问题讨论】:

    标签: react-native authentication amazon-cognito amplify


    【解决方案1】:

    这样结束了:

        AWS.config.update({
            accessKeyId: "YOUR_ACCESS_KEY",
            secretAccessKey: "YOUR_SECRET_ACCESS_KEY,
            region: "YOUR_REGION"
        });
        
        const params = {
            UserPoolId: 'THE_USER_POOL_ID',
            AttributesToGet: [
              'email',
            ],
        };
        const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
    
        cognitoidentityserviceprovider.listUsers(params, (err, data) => {
            if (err) {
                console.log(err);
            }
            else {
                console.log("data", data);
            }
        })
    

    现在的问题是必须将访问密钥存储在设备上,而我无法做到这一点。可能会在 Datastore 中创建另一个表来存储用户信息以供查询。

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 2021-06-04
      • 2019-06-21
      • 2017-01-04
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      相关资源
      最近更新 更多