amazon-web-services - AWS Cognito,放大 - 名称属性未与 currentauthenticateduser 一起显示
问题描述
我正在尝试使用 Auth.currentAuthenticatedUser 显示与 AWS 帐户关联的用户名称属性,但无法使其正常工作。属性显示在控制台日志中,但“名称”返回为未定义。如果我取出“名称”,则不再有错误,但屏幕上也没有显示文本。
我无法弄清楚为什么它似乎在读取 userInfo.attributes 而不是 userInfo.attributes.name。
import React, { useEffect, useState } from 'react';
import { ScrollView, Text, View } from 'react-native';
import { Auth } from "aws-amplify";
const ProfileScreen = ({navigation}) => {
const userInfo = Auth.currentAuthenticatedUser();
userInfo.then(function(result) {
console.log(result)
})
return (
<ScrollView>
<View>
<Text>
{userInfo.attributes.name}
</Text>
</View>
</ScrollView>
);
}
export default ProfileScreen;
解决方案
推荐阅读
- python - 显示情节标签而不悬停
- python - Django+Angular 2 合二为一
- javascript - 从提交表单中获取输入值并存储在 redux 存储中以供以后使用
- c# - 为什么我使用 Intrinsics API 比简单的解决方案慢?
- java - 将 PrivateKey 编码为 PKCS#1 格式,然后恢复为 PrivateKey
- android - 解决游戏商店问题;请求应用程序访问
- javascript - 数据标签错误地放置在条形图上 - chartjs
- python - 如何让我的 python 编码猜谜游戏替换已正确猜到的字母?
- java - Spring JPA在没有级联的情况下保存到存储库时获取错误分离实体传递以保持单向OneToOne关系
- javascript - fs.appendFile 不追加到新行