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.

federatedInfo from cache is null

See original GitHub issue

Describe the bug

In my React application, I use Google SignIn with AWS Cognito exactly as shown here.

First up: THANK YOU VERY MUCH for the awesome documentation - super helpful and clearly one of the reasons why AWS in general and AWS Amplify especially stand out from the rest! ❤️ 👍 💯

Now, I get valid and plausible credentials using const credentials = await Auth.federatedSignIn(...).

However, when I proceed to retrieve a JWT token using const federatedInfo = Cache.getItem('federatedInfo');, federatedInfo is always null.

When I look at Chrome DevTools > Storage > Local Storage, clear the cache and log back in using Google SignIn, I see how an aws-amplify-federatedInfo key is added with plausible contents, e.g.:

{
  expires_at: 159 ... 044
  provider: "google"
  token: "eyJ ... xxw"
  user:
  {
    id: "us-east-1:f16 ... 2db",
    email: "<redacted>",
    name: "<redacted>"
  }
}

Further, when I list all cache items using Cache.getAllKeys(), all I get is one unrelated AWSPinpoint_3f38 ... b64 key, although the Chrome Dev Console shows more keys.

What am I doing wrong?

To Reproduce

Run code from official AWS docs referenced above.

Expected behavior

Expected Cache.getItem('federatedInfo'); to return info on the federated user.

Code Snippet

See code in official AWS docs referenced above.

Environment

$ npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 52.19 MB / 16.00 GB
    Shell: 5.0.18 - /usr/local/bin/bash
  Binaries:
    Node: 14.5.0 - /usr/local/bin/node
    npm: 6.14.7 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 84.0.4147.89
    Firefox: 77.0.1
    Safari: 13.1.2
  npmPackages:
    @aws-amplify/core: ^3.4.2 => 3.4.2
    @aws-amplify/pubsub: ^3.0.20 => 3.0.20
    @sentry/browser: ^5.19.2 => 5.19.2
    @storybook/addon-actions: ^5.3.19 => 5.3.19
    @storybook/addon-links: ^5.3.19 => 5.3.19
    @storybook/addons: ^5.3.19 => 5.3.19
    @storybook/preset-create-react-app: ^3.1.4 => 3.1.4
    @storybook/react: ^5.3.19 => 5.3.19
    aws-amplify: ^3.0.20 => 3.0.20
    aws-amplify-react: ^4.1.19 => 4.1.19
    bootstrap: ^4.5.0 => 4.5.0
    google-auth-library: ^6.0.5 => 6.0.5
    react: ^16.13.1 => 16.13.1
    react-bootstrap: ^1.2.2 => 1.2.2
    react-dom: ^16.13.1 => 16.13.1
    react-google-button: ^0.7.1 => 0.7.1
    react-redux: ^7.2.0 => 7.2.0
    react-router-dom: ^5.2.0 => 5.2.0
    react-scripts: ^3.4.1 => 3.4.1
    redux: ^4.0.5 => 4.0.5
    uuid: ^8.2.0 => 8.2.0
  npmGlobalPackages:
    npm-check-updates: 7.0.2
    npm: 6.14.7
    ttab: 0.6.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dd-ssccommented, Jul 24, 2020

Update

As a workaround, I am able to obtain the federated info I need as described here:

const federatedInfo = localStorage.getItem("aws-amplify-federatedInfo");

I don’t know where localstorage comes from, might be some builtin React or browser thing; I don’t care, this gets me what I need.

0reactions
github-actions[bot]commented, Sep 19, 2021

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

Top 5 @aws-amplify/cache Code Examples - Snyk
Learn more about how to use @aws-amplify/cache, based on @aws-amplify/cache code examples ... removeItem("federatedInfo"); localStorage.clear(); Auth.
Read more >
Utilities - Cache - JavaScript - AWS Amplify Docs
Retrieves an item from the cache. It will return null if the item doesn't exist or it has expired.
Read more >
AWS Amplify Cache Utility usage - react native - Stack Overflow
I am trying to save and retrieve data in a React Native app using the Cache Utility provide by AWS Amplify. I used...
Read more >
https://unpkg.com/@aws-amplify/auth@4.1.2/src/Auth.ts
rejectNoUserPool(); } let username: string = null; let password: string = null ... to sync cache info into memory', e); throw e; }...
Read more >
Bing's Tech Notes - Amplify - Google Sites
Cache.getItem('federatedInfo').user; otherwise; currentUserPoolUser(); otherwise ... currentUserPoolUser; otherwise null; assemble attributes from Auth.
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