question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth.currentAuthenticatedUser returning cached custom attributes instead of current from user store

See original GitHub issue

Describe the bug When registering a user let’s say I set a custom attribute in cognito to A. Later in the registration process I then update it to B. When I call Auth.currentAuthenticatedUser it will still return A. The user needs to logout and log back in to get the latest value.

To Reproduce

  1. Create a user with a custom attribute and set it to X
  2. Update it to Y
  3. Call Auth.currentAuthenticatedUser
  4. Observe that you still see X even though in the user store it’s updated to Y

Expected behavior I expect the latest/most current attribute value to be returned.

Environment
  System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
    CPU: (4) x64 Intel(R) Core(TM) i5-6402P CPU @ 2.80GHz
    Memory: 1.71 GB / 15.60 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 12.15.0 - /usr/bin/node
    npm: 6.13.4 - /usr/bin/npm
  Browsers:
    Chrome: 80.0.3987.106
    Firefox: 73.0.1
  npmGlobalPackages:
    npm: 6.13.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danwritecodecommented, Mar 13, 2020

It’s a private Repo. I can reference important code pieces though.

Upon signup I’m setting two custom attributes, the second is the important one here:

signUp() {
  this.signUpPosting = true
  const { username, password } = this.signUpForm;

  Auth.signUp({ username, password, attributes: { "custom:UserType": "Realtor", "custom:Rltr_LicenseCnfrm_Cd": "0"}})
    .then(response => (this.signUpPosting = false, (this.stepNum = 1)))
    .catch(error => (console.log(error), this.signUpPosting = false));
}

Upon confirming that the license is correct, I set that custom attribute to “1”. I do this on my backend:

response = client.admin_update_user_attributes(
    UserPoolId=cognitoUserPoolId,
    Username=userId,
    UserAttributes=[
        {
            'Name': 'custom:Rltr_LicenseCnfrm_Cd',
            'Value': "1"
        },
    ]
)

Now back on my frontend if I am to call the Auth.currentAuthenticatedUser() function, it still returns a 0 even though in Cognito I see that it is now a 1.

Only way I’ve found to get the fresh value is by logging out then in again.

I can work around this by making an additional API call myself, but it would be nice if I could get it through the amplify api.

0reactions
github-actions[bot]commented, Jun 8, 2022

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication - Managing user attributes - JavaScript
Authentication. Managing user attributes. In Cognito, you have the ability to manage both standard and custom user attributes for your users.
Read more >
Retrieve user's name and email after aws-amplify federated ...
I kinda answered my own question. After authenticating with. Auth.federatedSignIn({provider: 'Google'});. I ran the following code: Auth.
Read more >
AWS Cognito & Amplify Auth - Bad, Bugged, Baffling
This would be another easy fix for Cognito. Anyway let's move on. Custom attributes are a MESS #. When you want to store...
Read more >
Role-based access control using Amazon Cognito and an ...
An AWS Lambda function named PreTokenGeneration reads the custom:groups custom attribute and converts it to a JSON Web Token (JWT) claim named ...
Read more >
Authentication - Test Page
AWS Amplify uses User Pools to store your user information and handle ... SMS messages for Multi-Factor Authentication; Customize attributes for your users, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found