Amplify-js: login data not saved in AsyncStorage, auth state not persisted

Created on 1 Sep 2019  路  11Comments  路  Source: aws-amplify/amplify-js

Describe the bug
As state here, auth state is persisted using AsyncStorage - this used to work in my app but now auth state is not persisted and user is logged out every time he opens the app, console.loging all keys from async storage I don't get anything from amplify, only keys that I have set myself.

To Reproduce
Steps to reproduce the behavior:

  1. Create react native app
  2. set up amplify
  3. create log in form and log in with it
  4. exit app
  5. enter app again - you are logged out

Expected behavior
User auth state should be saved, as state in the link above it should be in AsyncStorage

Additional context
Something that can cause this is the fact that react-native removed the AsyncStorage module and moved it to a package called @react-native-community/async-storage so you may need to add this package and update your imports, everything should be the same other than that.

This is a crucial part of every application that is using authentication - users can't be expected to log in every time they open the app

Auth React Native pending-close-response-required

Most helpful comment

I'm also having this issue. Can we get #3991 or #4027 merged?

All 11 comments

I have the same problem but only in ios, if I close the application or reload it I get not authenticated when I call the Auth.currentAuthenticatedUser(). In android it works as expected.

@haverchuck AsyncStorage is related to react-native and not ionic

@idanlo - you're right; my mind was already in Ionic-land. The error is corrected.

Me too, I temporary fixed it removing @react-native-community/async-storage . :(

In my case I have solved it by making a copy of StorageHelper but using AsyncStorage from @ react-native-community/async-storage instead of react-native and then using in this way:

Amplify.configure({
  Auth: {
    // ...
    storage: new StorageHelper().getStorage()
  }
});

I think the general solution is updating that dependency here with the new package https://github.com/react-native-community/async-storage

I tried the custom StorageHelper but for some reason it doesn't work for me. In my app it tries to call currentAuthenticatedUser when it launches, but that promise never returns. Doesn't resolve, doesn't reject. Nothing logged.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

I'm also having this issue. Can we get #3991 or #4027 merged?

+1 lets get this merged.

I created another issue (#4272) since this one is already buried in the issues list

Was this page helpful?
0 / 5 - 0 ratings