如何在我的Amplify-React项目中查找“user”的属性?

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

How do I find out the attributes of a 'user' in my Amplify-React project?

问题

<Heading level={1}>你好 {user.username}</Heading>

我已经在项目文件中搜索了很久,想找出'user'具有哪些属性。显然,它具有一个'username'属性,但我想更改标题,使其显示“你好 {user.firstname}”。但是'firstname'不起作用,所以我想知道在我的项目中哪里可以找到用户的属性,以便我可以将标题更改为他们的名字。

英文:

So some of the default code that is provided when you create an Amplify-React app looks like this:

<Heading level={1}>Hello {user.username}</Heading>

I have tried searching all over my project's files to find out what attributes 'user' has. Clearly it has a 'username' attribute, but what I'd like to change is the heading so that it says "Hello {user.firstname}". Firstname doesn't work so I was wondering where in my project I can find the attributes that a user has so that I can change the heading to their first name.

答案1

得分: 0

使用Auth.currentUserInfo()应该返回以下类似的对象:

{
  "attributes": {
    "email": "我的电子邮件地址",
    "email_verified": true,
    "sub": "内部用户ID:XXXX-XXXX-XXXX-XXXX-XXXX"
  },
  "id": "us-east-1:XXXX",
  "username": "我的用户名"
}

参考链接

由于这个函数是异步的,确保在将其设置为变量时使用await

英文:

Using Auth.currentUserInfo() should return you an object like this:

{
  "attributes": {
    "email": "MY EMAIL ADDRESS",
    "email_verified": true,
    "sub": "INTERNAL USERID: XXXX-XXXX-XXXX-XXXX-XXXX"
  },
  "id": "us-east-1:XXXX",
  "username": "MY USERNAME"
}

Reference

As this function is asynchronous, be sure to await it when setting it to a variable.

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

发表评论

匿名网友

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

确定