Amplify-js: AsyncStorage wrong import - removed from react-native and moved to different package

Created on 27 Oct 2019  路  13Comments  路  Source: aws-amplify/amplify-js

Describe the bug
AsyncStorage has been removed from react-native and moved to a new package @react-native-community/async-storage which means developers that have react-native version >=0.60 doesn't have the functionality that is related to async storage. So for example when users exit the app the login data is not saved and they need to login again, which is very frustrating. I have looked at your code and there are many files that use AsyncStorage from react-native, this needs to be changed to the new package @react-native-community/async-storage

React Native bug

Most helpful comment

@Amplifiyer I believe this is the source of the Auth https://github.com/aws-amplify/amplify-js/issues/4260#issuecomment-546551532 bug. Please release an unstable version as it's a major blocker.

All 13 comments

There is PR open for this already #4027

@Amplifiyer I believe this is the source of the Auth https://github.com/aws-amplify/amplify-js/issues/4260#issuecomment-546551532 bug. Please release an unstable version as it's a major blocker.

Kindly ask maintainers to accept the PR. We are frozen on two projects due to the lack of persistent auth.

There is PR open for this already #4027

@alisherakb you can configure a custom storage. It's quite easy

Amplify.configure(aws_config);
Auth.configure({
    storage: AmplifyStorage
});

@usmansbk Thanks for the suggestion. I copied your code snippet to App.js, copied custom Storage class from the doc provided.
However, the issue persists. It throws user after first reload:
Screenshot 2019-10-29 at 12 42 22

Here is the gist with custom storage class:
https://gist.github.com/alisherakb/1d5f51f3673806e429f36cb58ed1052f

@usmansbk Yes, I鈥檝e added Auth.configure with custom storage within it right below Amplify.configure.

This is what finally worked for me in my App.tsx -

https://gist.github.com/JamieLivi/fc14460735b49b291fd62862df432752

With the following in package.json:

"amazon-cognito-identity-js": "^3.1.3",
"aws-amplify": "^1.2.3",
"aws-amplify-react-native": "^2.2.3",
"aws-appsync": "^2.0.1",
"aws-appsync-react": "^2.0.1",

Hope this helps mate, was stuck on this for fracking ages.

This is what finally worked for me in my App.tsx -

https://gist.github.com/JamieLivi/fc14460735b49b291fd62862df432752

With the following in package.json:

"amazon-cognito-identity-js": "^3.1.3",
"aws-amplify": "^1.2.3",
"aws-amplify-react-native": "^2.2.3",
"aws-appsync": "^2.0.1",
"aws-appsync-react": "^2.0.1",

Hope this helps mate, was stuck on this for fracking ages.

I have followed your example, but getting the same error as in the last screenshot: YellowBox.js:71 Possible Unhandled Promise Rejection (id: 0): "not authenticated"
after the first app reload.

@alisherakb you should try the unstable versions. That's the version I'm using.

    "aws-amplify": "1.2.4-unstable.5",
    "aws-amplify-react-native": "2.2.4-unstable.5",
    "aws-appsync": "^2.0.1",
    "aws-appsync-react": "^2.0.1",
    react: ^16.11.0 => 16.11.0
    react-native: ^0.61.2 => 0.61.2

@usmansbk I updated my dependencies to unstable ones:
"aws-amplify": "^1.2.4-unstable.5", "aws-amplify-react-native": "2.2.4-unstable.5"

But the situation hasn't changed for me. (see my comment above for screenshot).
My init file:
https://gist.github.com/alisherakb/607255c51d1587d2156eef24310c618b

I need your help guys.

The amplify documentation covers how to set the storage provider for AUTH (https://aws-amplify.github.io/docs/js/authentication#managing-security-tokens) and provides an example with ASYNC storage.

A short term fix for those affected should take that example but import "@react-native-community/async-storage" - there's no API changes between the old bundled DEP and the new community version.

Very easy and works.

Cheers

Resolving issue as the above PR was merged in order to resolve the Async Storage community edition

If user has challenge to change password, Amplify will consider user as not logged in, Lol
I just spend hours thought it's AsyncStorage issue, but found user just need to change password....
https://github.com/aws-amplify/amplify-js/issues/1715

Was this page helpful?
0 / 5 - 0 ratings