【问题标题】:How do I retrieve updated user attributes from AWS Cognito after calling Auth.updateUserAttributes调用 Auth.updateUserAttributes 后如何从 AWS Cognito 检索更新的用户属性
【发布时间】:2019-12-29 18:47:38
【问题描述】:

我在登录时或更新用户属性后无法从 AWS Cognito 获取最新用户信息。

我正在使用 aws-amplify 进行身份验证,并且注册和登录工作正常。

问题出现在我的个人资料页面上。我允许人们注册通知以及更改他们个人资料中的其他数据。我已通过记录响应验证了更改已在后端以及控制台中成功进行。

但是,当我调用 Auth.currentAuthenticatedUser() 时,我得到了之前缓存的信息。

收到成功响应后如何检索更新的用户属性?

    async () => {
      const { email, given_name, family_name, preferred_username, "custom:notifyPredictRemind": customNotifyPredictRemind, "custom:notifyPredictResult": customNotifyPredictResult } = this.state;
      let params = { email, given_name, family_name, preferred_username, "custom:notifyPredictRemind": customNotifyPredictRemind, "custom:notifyPredictResult": customNotifyPredictResult } 
      let updateResult = await Auth.updateUserAttributes(user, params) // returns SUCCESS
      let user = await Auth.currentAuthenticaterUser()
    }

我希望最后调用 currentAuthenticaterUser 以返回更新的用户信息。任何想法我该怎么做?谢谢。

【问题讨论】:

    标签: react-native amazon-cognito aws-amplify


    【解决方案1】:

    想通了。有一个名为 bypassCache 的参数,您可以将其传递给 currentAuthenticatedUser() 以刷新用户信息。对于初始登录和 Cognito 配置文件的更新很有用。

    async () => {
      const { email, given_name, family_name, preferred_username, "custom:notifyPredictRemind": customNotifyPredictRemind, "custom:notifyPredictResult": customNotifyPredictResult } = this.state;
      let params = { email, given_name, family_name, preferred_username, "custom:notifyPredictRemind": customNotifyPredictRemind, "custom:notifyPredictResult": customNotifyPredictResult } 
      let updateResult = await Auth.updateUserAttributes(user, params) // returns SUCCESS
      let user = await Auth.currentAuthenticaterUser({bypassCache: true}) // UPDATED, NOW WORKS
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2022-10-02
      • 2018-01-05
      • 2021-03-09
      • 1970-01-01
      • 2018-08-25
      • 2017-11-03
      • 2017-08-12
      • 2021-11-27
      相关资源
      最近更新 更多