英文:
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"
}
As this function is asynchronous, be sure to await
it when setting it to a variable.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论