代码之家  ›  专栏  ›  技术社区  ›  Michel

改变Cognito用户池/AWS放大;导致注册问题

  •  0
  • Michel  · 技术社区  · 7 年前

    我正在使用AWS Amplify(和Cognito)在iOS应用程序中处理一些注册/登录过程。

    它运行得很好,但后来我决定在注册时需要更多的信息。 即:姓名、名、姓。

    以下是为进行身份验证而调用的函数:

    func showSignIn() {
        AWSAuthUIViewController
            .presentViewController(with: self.navigationController!,
                                   configuration: nil,
                                   completionHandler: {
                                    (provider: AWSSignInProvider, error: Error?) in
                                    if error != nil {
                                        print("Error occurred: \(String(describing: error))")
                                    } else {
                                        print("Identity provider: \(provider.identityProviderName)")
                                    }
            })
    }
    

    在我做了必要的操作(使用amplify cli)以删除旧用户池并创建新用户池之后。我重新编译了我的iOS应用程序并启动了它。

    这还可以,但现在当我想注册一个用户时,我会收到以下消息:

    enter image description here

    消息内容并不奇怪,因为现在我需要指定的字段。 但问题是,我在UI中看不到任何可以输入这些新字段的空间。

    我是不是忘了做些什么来充分更新UI? 或者我应该通过修改上面的函数来做些什么(手动更新UI)?如果是,改变的方式是什么?

    这是我使用amplify的第一步,我可能会犯一些基本的错误。

    1 回复  |  直到 7 年前
        1
  •  1
  •   J. Hesters    7 年前

    我只在JavaScript中使用AWS Amplify,但在JS中,您确实需要手动更新UI。

    下面是JS代码,以及我如何手动调用它,也许这会有所帮助。

    handleSignUpPressed = async ({
      emailAddress = '',
      firstName = '',
      lastName = '',
      password = '',
      phoneNumber = '',
      wantsToImproveApp = true,
    } = {}) => {
      if (emailAddress && firstName && lastName && password && phoneNumber) {
        try {
          const res = await Auth.signUp({
            username: emailAddress,
            password,
            attributes: {
              email: emailAddress,
              name: firstName,
              family_name: lastName,
              phone_number: phoneNumber,
            },
          });
          console.log('success', res);
          this.props.navigation.push('VerificationScreen', {
            username: res.username,
          });
        } catch (err) {
          console.log(err);
        }
      }
    };
    
        2
  •  0
  •   Lawmicha    6 年前

    您可以使用AWSMobileClient来显示Auth中的下拉列表 https://aws-amplify.github.io/docs/ios/authentication#user-attributes 在盖子下面使用AWSAUTHUIVEWCONTROLLER。

    我没有看到为您的用例定制符号的方法。还有一个现有的RFC来提高AWSMobileClient和下拉式UI的可用性: https://github.com/aws-amplify/aws-sdk-ios/issues/1158

    如果您启动自己的注册/登录流,那么可以将用户属性传递给 AWSMobileClient.signUp : https://aws-amplify.github.io/docs/ios/authentication#user-属性