简体   繁体   English

无法使用 aws-amplify 从 cognito 获取更新的属性及其值

[英]Unable to get updated attributes and their values from cognito with aws-amplify

Unable to get current attributes and their values from Cognito无法从 Cognito 获取当前属性及其值

Here is the complete flow of what I did这是我所做的完整流程

  1. successfully logged in with aws-amplify使用 aws-amplify 成功登录
  2. const cognitoUser = await Auth.currentAuthenticatedUser(); const cognitoUser = 等待 Auth.currentAuthenticatedUser(); console.log("cognitoUser", cognitoUser); console.log("cognitoUser", cognitoUser);
  3. got the Cognito user attributes info which is all correct (name, sub, email, email_verified)得到了所有正确的 Cognito 用户属性信息(名称、子、email、email_verified)
  4. called a backend API to update the user info (added one more attribute "profile": 1)调用后端 API 来更新用户信息(添加了一个属性“profile”:1)
  5. checked from Cognito user pool, it was successfully added and "profile": 1 was there从 Cognito 用户池中检查,它已成功添加并且 "profile": 1 在那里
  6. again I did const cognitoUser = await Auth.currentAuthenticatedUser();我又做了 const cognitoUser = await Auth.currentAuthenticatedUser(); console.log("cognitoUser", cognitoUser); console.log("cognitoUser", cognitoUser);
  7. got the old result again (name, sub, email, email_verified).再次得到旧结果(名称,子,email,email_verified)。 "profile": 1 was not there “个人资料”:1 不存在
  8. successfully signed out with aws-amplify使用 aws-amplify 成功退出
  9. logged in again再次登录
  10. the keys this time got from the console.log are (name, sub, email, email_verified, profile)这次从 console.log 得到的键是 (name, sub, email, email_verified, profile)

after searching a lot I found the answer.经过大量搜索,我找到了答案。 there is something called bypass cache.有一种叫做绕过缓存的东西。 this is how we can use it这就是我们可以使用它的方式

import { Auth } from 'aws-amplify';

Auth.currentAuthenticatedUser({
    bypassCache: false  // Optional, By default is false. If set to true, this call will send a request to Cognito to get the latest user data
}).then(user => console.log(user))
.catch(err => console.log(err));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM