大佬教程收集整理的这篇文章主要介绍了AWS Amplify,等待 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 中我得到这个:
@H_448_7@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}
因此,在调用该函数时,我在 @H_448_7@myAttribute 中得到了一些奇怪的输出,但是来自 Cognito 的真实数据稍后会在 userInfo
我怎样才能获得关于 @H_448_7@myAttribute 的真实数据?
在您对 getMyAttribute()
的呼叫站点上,您似乎缺少一个 async
关键字。
是否改变线路
const myAttribute = getMyAttribute();
到
const myAttribute = async getMyAttribute();
提高输出?
从您的代码来看,getMyAttribute 是 promise 方法。这就是为什么你在调用它时会得到异步进程。要正确调用它,您必须使用 async - await 并且您已经完成了其他问题。其他方式,你试过这个吗?
let myAttribute;
getMyAttribute().then(attribute => {
myAttribute = attribute;
})
以上是大佬教程为你收集整理的AWS Amplify,等待 Auth.currentUserInfo全部内容,希望文章能够帮你解决AWS Amplify,等待 Auth.currentUserInfo所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。