JavaScript: AWS Amplify : How to get the User Id(Sub ID) after user signs Up. After SignsUP not Sign In

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

JavaScript: AWS Amplify : How to get the User Id(Sub ID) after user signs Up. After SignsUP not Sign In

问题

我正在使用由Aws Amplify提供的Auth模块。我在思考用户注册后如何检索userID。

我可以在用户登录后获取ID,但我希望在注册过程中获取userID,以便在登录之前更新我的一些模型。

我在注册响应中没有看到userID。我想知道是否有任何解决方法?

英文:

I am using the Auth Module Provided by Aws Amplify.I am contemplating how can I retrieve the
userID once the user signs up.

I can get the ID once the user Signs In, however, I want to get the userID during SignUp Process so I can update some of my model before logging in.

I didn't see userId in my signUp response. I am wondering if there is any workaround for that ?

答案1

得分: 0

Id包含在响应的userSub部分中,因此是result.userSub

  1. Auth.signUp({
  2. username: username,
  3. password: password,
  4. attributes: attributes
  5. }).then((result) => {
  6. console.log(result.userSub)
  7. })

响应评论:

从signUp的结果是:

  1. {
  2. user: CognitoUser;
  3. userConfirmed: boolean;
  4. userSub: string;
  5. }

来源:https://docs.amplify.aws/lib/auth/emailpassword/q/platform/js/#sign-up

英文:

The Id is contained in the userSub part of the response, so result.userSub.

  1. Auth.signUp({
  2. username: username,
  3. password: password,
  4. attributes: attributes
  5. }).then((result) => {
  6. console.log(result.userSub)
  7. })

In response to comment:

The result from signUp is:

  1. {
  2. user: CognitoUser;
  3. userConfirmed: boolean;
  4. userSub: string;
  5. }

Source: https://docs.amplify.aws/lib/auth/emailpassword/q/platform/js/#sign-up

huangapple
  • 本文由 发表于 2023年3月7日 13:04:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658209.html
匿名

发表评论

匿名网友

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

确定