javascript - AWS 放大,等待 Auth.currentUserInfo
问题描述
我需要从 Cognito 获取一些自定义属性,并使用该信息做一些事情。
我有这个功能:
const getMyAttribute = async (): string => {
const userInfo = await Auth.currentUserInfo();
console.log('userInfo', userInfo);
return userInfo.attributes['custom:myAttribute']
};
我在这里用一些 React 组件调用它:
const myAttribute = getMyAttribute();
console.log('myAttribute:', myAttribute); // Here is weird output
// Here I need to do something with `myAttribute`
在 console.log 我得到这个:
myAttribute: {"_40": 0, "_55": null, "_65": 0, "_72": null}
userInfo: {"attributes": {"custom:myAttribute": "6", "email": "testpending4@test.cl", "sub": "etc..."}, ... rest of user info data from Cognito}
所以,我myAttribute
在调用函数时得到了一些奇怪的输出,但来自 Cognito 的真实数据稍后会出现userInfo
我怎样才能得到真实的数据myAttribute
呢?
解决方案
在您的呼叫站点上,getMyAttribute()
您似乎缺少一个async
关键字。
换线
const myAttribute = getMyAttribute();
可以
const myAttribute = async getMyAttribute();
提高产量吗?
推荐阅读
- scala - Scala - 方法变量不是不可变的
- flutter - Flutter 在 ListView 中显示数据一次
- alignment - 有没有比用`#noqa`结束每一行更好的方法来禁用对齐代码块上的警告和错误?
- java - 如何将实体对象保存到具有生成索引的初始化 h2 表中?
- c# - 数据集不支持 System.Nullable<>。' 实体框架
- algorithm - 最小的字典字符串
- typescript - Typescript 在数组解构后抱怨变量类型
- python - 引发 NodeNotFoundError
- javascript - 按值查找嵌套数组
- javascript - 如何在不更改单个数组的情况下从嵌套数组中删除所有属性