Using AsyncStorage overwrites Amplify JWT's
See original GitHub issueBug: 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:
- Created 4 years ago
- Reactions:4
- Comments:10
See my comment on issue #4351, I fixed this temporarily by implementing a custom storage class.
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.