Sure, here’s the translation: 如何使用 Amplify 和 Android 注册用户并添加属性。

huangapple go评论89阅读模式
英文:

How do i sign a user up and add attributes with Amplify and Android

问题

当使用Amplify创建用户时,我正在调用amplify.createUser(email, password)。

在使用Cognito时,您可以使用Auth.SignUp()并使用attributes参数,将Cognito用户池属性分配给用户。是否有任何方法在Amplify中实现这样的操作?

我基本上想要注册一个用户并同时设置一些Cognito用户池属性。

英文:

When creating a user with Amplify, I am calling amplify.createUser(email, password).

When using Cognito, you can use Auth.SignUp() with an attributes parameter to assign Cognito user pool attributes to the user. Is there anyway to do this with Amplify?

I basically want to sign up a user and set some Cognito user pool attributes at the same time.

答案1

得分: 3

这个功能在 Amplify for Android 中尚未实现,但计划在不久的将来完成,详见此文档。请定期查阅文档以获取更新的可用信息。

与此同时,您仍然可以使用 Amplify。只需通过身份验证逃生通道访问基础的 AWSMobileClient,该通道支持传递自定义属性。有关如何准确使用 AWSMobileClient 的更多详细信息,请参阅此文档

英文:

This functionality has not yet been implemented in Amplify for Android but is scheduled to be finished in the near future, as noted in this documentation. Please check back to the documentation for updates on availability.

In the meantime though, you can still use Amplify. Just access the underlying AWSMobileClient through the authentication escape hatch, which does support passing custom attributes. See this documentation for more details on how exactly to use AWSMobileClient.

答案2

得分: 1

Here's the translated code:

首先,您需要创建一个 AuthSignUpOptions 对象(以下是自定义属性和标准属性的示例):

AuthSignUpOptions options = AuthSignUpOptions.builder()
                        .userAttribute(AuthUserAttributeKey.custom("custom:role"), "some_role")
                        .userAttribute(AuthUserAttributeKey.address(), "some_address")
                        .build();

然后调用 Amplify.Auth.signup 方法:

Amplify.Auth.signUp("username", "password", options,
                        result -> { /* 进行操作 */ },
                        error -> { /* 进行操作 */ });

将其整合起来如下所示:

AuthSignUpOptions options = AuthSignUpOptions.builder()
        .userAttribute(AuthUserAttributeKey.custom("custom:role"), "some_role")
        .userAttribute(AuthUserAttributeKey.address(), "some_address")
        .build();
Amplify.Auth.signUp(tempUsername.getText().toString(), pin.getText().toString(), options,
        result -> { /* 进行操作 */ },
        error -> { /* 进行操作 */ });
英文:

I don't know if this is still relevant, but here is how to accomplish the task with Amplify.

First you build an AuthSignUpOptions object (example of custom attribute and standard attribute below):

AuthSignUpOptions options = AuthSignUpOptions.builder()
                        .userAttribute(AuthUserAttributeKey.custom("custom:role"), "some_role")
                        .userAttribute(AuthUserAttributeKey.address(), "some_address")
                        .build();

Then call Amplify.Auth.signup:

Amplify.Auth.signUp("username", "password", options,
                        result -> { /* do something */ },
                        error -> { /* do something */ });            

Altogether it looks like this:

AuthSignUpOptions options = AuthSignUpOptions.builder()
        .userAttribute(AuthUserAttributeKey.custom("custom:role"), "some_role")
        .userAttribute(AuthUserAttributeKey.address(), "some_address")
        .build();
Amplify.Auth.signUp(tempUsername.getText().toString(), pin.getText().toString(), options,
        result -> { /* do something */ },
        error -> { /* do something */ });

huangapple
  • 本文由 发表于 2020年8月14日 18:46:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63411273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定