Unable to get current attributes and their values from Cognito
Here is the complete flow of what I did
- successfully logged in with aws-amplify
- const cognitoUser = await Auth.currentAuthenticatedUser();
console.log("cognitoUser", cognitoUser);
- got the Cognito user attributes info which is all correct (name, sub, email, email_verified)
- called a backend API to update the user info (added one more attribute "profile": 1)
- checked from Cognito user pool, it was successfully added and "profile": 1 was there
- again I did const cognitoUser = await Auth.currentAuthenticatedUser();
console.log("cognitoUser", cognitoUser);
- got the old result again (name, sub, email, email_verified). "profile": 1 was not there
- successfully signed out with aws-amplify
- logged in again
- the keys this time got from the console.log are (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));