首页 > 解决方案 > 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;

标签: amazon-web-servicesreact-nativeauthenticationamazon-cognitoaws-amplify

解决方案


推荐阅读