Tanmoy Bhowmick
Tanmoy Bhowmick

Reputation: 1481

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

Unable to get current attributes and their values from Cognito

Here is the complete flow of what I did

  1. successfully logged in with aws-amplify
  2. const cognitoUser = await Auth.currentAuthenticatedUser(); console.log("cognitoUser", cognitoUser);
  3. got the Cognito user attributes info which is all correct (name, sub, email, email_verified)
  4. called a backend API to update the user info (added one more attribute "profile": 1)
  5. checked from Cognito user pool, it was successfully added and "profile": 1 was there
  6. again I did const cognitoUser = await Auth.currentAuthenticatedUser(); console.log("cognitoUser", cognitoUser);
  7. got the old result again (name, sub, email, email_verified). "profile": 1 was not there
  8. successfully signed out with aws-amplify
  9. logged in again
  10. the keys this time got from the console.log are (name, sub, email, email_verified, profile)

Upvotes: 4

Views: 1450

Answers (1)

Tanmoy Bhowmick
Tanmoy Bhowmick

Reputation: 1481

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));

Upvotes: 8

Related Questions