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.

Using AsyncStorage overwrites Amplify JWT's

See original GitHub issue

Bug: using AsyncStorage from @react-native-community/async-storage causes the Cognito JWT’s that were being retrieved by Auth.currentSession().

Behavior without AsyncStorage: Auth.signIn() returns a Cognito session that persists on the emulator through reload.

Behavior after adding the following code:

      try {
        let temporaryPassword = await AsyncStorage.getItem('@temporaryPassword')
        console.log(temporaryPassword)
        if(temporaryPassword !== null) {
          console.log('not null')
          this.setState({ temporaryPassword: temporaryPassword})
        } else {
          temporaryPassword = Math.random().toString(36).substr(2, 8) 
          await AsyncStorage.setItem('@temporaryPassword', temporaryPassword)
          console.log('setting: ', temporaryPassword)
          this.setState({ temporaryPassword: temporaryPassword})
        }
      } catch(e) {
        console.log(e)
      }

After implementing this code, the JWT’s are overwritten on refresh for no apparent reason. Auth.currentSession() accordingly fails with no current session.

What the behavior should be: Writing to AsyncStorage should leave Auth.currentSession() intact and returning values. The user should be able to AsyncStorage.setItem(‘x’, ‘y’), reload the device, and then still see a response from Auth.currentSession().

Versions: “aws-amplify”: “^1.1.36”, “aws-amplify-react”: “^2.3.12”,

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

2reactions
ctomichaelcommented, Nov 6, 2019

See my comment on issue #4351, I fixed this temporarily by implementing a custom storage class.

0reactions
github-actions[bot]commented, Dec 26, 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

Save values multiple times with same properties in async ...
The requirement is: Save multiple (n) values in AsyncStorage, which needs to be fetched in order. Simplest way is to use an array....
Read more >
A guide to React Native's AsyncStorage - LogRocket Blog
AsyncStorage is an unencrypted and asynchronous data storage system in React Native that allows users to persist data offline.
Read more >
How To Use React Native AsyncStorage - JScrambler Blog
AsyncStorage is a simple, asynchronous, unencrypted by default module that allows you to persist data offline in React Native apps.
Read more >
API | Async Storage - GitHub Pages
Sets a string value for given key . This operation can either modify an existing entry, if it did exist for given key...
Read more >
Easily Persist Data with Context and AsyncStorage
The first thing we do is store the count value in AsyncStorage . The easiest way to do this is to use a...
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