mongodb / stitch-js-sdk

MongoDB Stitch JavaScript SDK
Apache License 2.0
113 stars 67 forks source link

Please Update the AsyncStorage to react-native-community/react-native-async-storage #278

Open ArmarJosh opened 5 years ago

ArmarJosh commented 5 years ago

React Native AsyncStorage is deprecated and replaced with react-native-community/react-native-async-storage. please update the package i don't want to ship my App with this deprecated AsyncStorage version.

adamchel commented 5 years ago

Hi @ArmarJosh , thanks for bringing this to our attention. We are working on updating the package version. I will let you know when this is released.

ArmarJosh commented 5 years ago

Hi Adam,Thanks for ur quick response. Waiting on your notification. 

Sent from Yahoo Mail for iPhone

On Monday, May 20, 2019, 5:53 PM, Adam Chelminski notifications@github.com wrote:

Hi @ArmarJosh , thanks for bringing this to our attention. We are working on updating the package version. I will let you know when this is released.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

adamchel commented 5 years ago

@ArmarJosh, I have a quick update. I've been looking into the react-native-community/react-native-async-storage package, and unfortunately it can't be used as a drop-in replacement for the built-in AsyncStorage.

The new community package makes use of native modules, which makes it incompatible with Expo. See https://github.com/react-native-community/react-native-async-storage/issues/72 for more context. Many of our users use Expo, so replacing AsyncStorage with this package would be a backwards-incompatible change.

There are two choices we can make here:

1.) Wait until Expo releases/announces how they will handle backwards compatibility with AsyncStorage.

2.) Build two storage libraries, one based on Expo’s SecureStore (https://docs.expo.io/versions/latest/sdk/securestore/), and one based on the community AsyncStorage package. Users would then be able to configure their desired storage library when initializing Stitch. This would also be a breaking change, but it would allow us to support both bare projects with native modules, and Expo-based projects.

Example:

// these currently do not exist
import { RNExpoStorage } from "mongodb-stitch-react-native-expo-storage";
import { RNAsyncNativeStorage } from "mongodb-stitch-react-native-async-storage";

let expoClient = Stitch.initializeAppClient(
    "your-client-app-id", 
    new StitchAppClientConfiguration.Builder()
        .withStorage(new RNExpoStorage())
        .build()
);

let nativeClient = Stitch.initializeAppClient(
    "your-client-app-id", 
    new StitchAppClientConfiguration.Builder()
        .withStorage(new RNAsyncNativeStorage())
        .build()
);

We believe that Expo will probably provide some sort of built-in backwards compatibility for AsyncStorage, since many users depend on it, so I think we’re going to wait on replacing the library until there is a clear plan from Expo on how this will be handled.

In the meantime, I’m happy to help you build a custom storage class that you can use to avoid using the deprecated AsyncStorage.

Are you currently using React Native with Expo or as a bare project with native modules?

ArmarJosh commented 5 years ago

Hi Adam. This is quite heart breaking.Am using the bare project native module, and i cant just use Expo, because their modules am using that are no supported by Expo.Since we are not sure when expo will handles backward-incompatibility. A Custom storage class would be highly appreciated.  Corry Armar  +256 776 653 528 or +250 789 523 060

On Monday, May 20, 2019, 7:33:47 PM GMT+3, Adam Chelminski <notifications@github.com> wrote:  

@ArmarJosh, I have a quick update. I've been looking into the react-native-community/react-native-async-storage package, and unfortunately it can't be used as a drop-in replacement for the built-in AsyncStorage.

The new community package makes use of native modules, which makes it incompatible with Expo. See react-native-community/react-native-async-storage#72 for more context. Many of our users use Expo, so replacing AsyncStorage with this package would be a backwards-incompatible change.

There are two choices we can make here:

1.) Wait until Expo releases/announces how they will handle backwards compatibility with AsyncStorage.

2.) Build two storage libraries, one based on Expo’s SecureStore (https://docs.expo.io/versions/latest/sdk/securestore/), and one based on the community AsyncStorage package. Users would then be able to configure their desired storage library when initializing Stitch. This would also be a breaking change, but it would allow us to support both bare projects with native modules, and Expo-based projects.

Example: // these currently do not exist import { RNExpoStorage } from "mongodb-stitch-react-native-expo-storage"; import { RNAsyncNativeStorage } from "mongodb-stitch-react-native-async-storage";

let expoClient = Stitch.initializeAppClient( "your-client-app-id", new StitchAppClientConfiguration.Builder() .withStorage(new RNExpoStorage()) .build() );

let nativeClient = Stitch.initializeAppClient( "your-client-app-id", new StitchAppClientConfiguration.Builder() .withStorage(new RNAsyncNativeStorage()) .build() ); We believe that Expo will probably provide some sort of built-in backwards compatibility for AsyncStorage, since many users depend on it, so I think we’re going to wait on replacing the library until there is a clear plan from Expo on how this will be handled.

In the meantime, I’m happy to help you build a custom storage class that you can use to avoid using the deprecated AsyncStorage.

Are you currently using React Native with Expo or as a bare project with native modules?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

adamchel commented 5 years ago

Okay, thanks for letting me know. Here's what I recommend doing

  1. Follow the instructions at https://github.com/react-native-community/react-native-async-storage#getting-started to install and link the community AsyncStorage package and native module to your app project.

  2. Add a new file to your project called RNCommunityAsyncStorage.ts (or .js if you're not using TypeScript).

  3. Copy the code from https://github.com/mongodb/stitch-js-sdk/blob/master/packages/react-native/core/src/core/internal/common/RNAsyncStorage.ts into this new file. If you're not using TypeScript, you'll need to remove any type annotations or typescript-specific syntax.

  4. In this file, change the line

import { AsyncStorage } from "react-native"

to

import AsyncStorage from '@react-native-community/async-storage';
  1. Rename the class in this file from RNAsyncStorage to RNCommunityAsyncStorage.

  2. In your app code, find the place where you call Stitch.initializeAppClient or Stitch.initializeDefaultAppClient. Replace it with the following:

Stitch.initializeAppClient(
    "your-client-app-id", 
    new StitchAppClientConfiguration.Builder()
        .withStorage(new RNCommunityAsyncStorage())
        .build()
);

If you have any questions or problems with this approach, let me know. In the long term, we'd like to offer this library ourselves, but as I've said above, we want to ideally do it in a backwards compatible way.

ArmarJosh commented 5 years ago

Hi Adam, Thanks for the instructions above.How ever am failing to properly convert the from TypeScript to JavaScript.. I have never used type script before thou.See link to my attempt code: https://github.com/ArmarJosh/Stich_Help/blob/master/RNCommunityAsyncStorage Any help on this will be appreciated. Thanx Armar. Corry Armar  +256 776 653 528 or +250 789 523 060

On Monday, May 20, 2019, 11:31:07 PM GMT+3, Adam Chelminski <notifications@github.com> wrote:  

Okay, thanks for letting me know. Here's what I recommend doing

import { AsyncStorage } from "react-native" to import AsyncStorage from '@react-native-community/async-storage';

Stitch.initializeAppClient( "your-client-app-id", new StitchAppClientConfiguration.Builder() .withStorage(new RNCommunityAsyncStorage()) .build() );

If you have any questions or problems with this approach, let me know. In the long term, we'd like to offer this library ourselves, but as I've said above, we want to ideally do it in a backwards compatible way.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

adamchel commented 5 years ago

Okay, try using this file:

https://gist.github.com/adamchel/6976979294e5a59c255e588ebdddfd8e

ArmarJosh commented 5 years ago

Hi Adam, Thanks a lot for this. it works.Though i have anew issue.. Not sure if its me doing something wrong, But when one logs in with passwordCreditals, and the app is refreshed the user is not remembered. it goes back to the login screen every-time.looks like the authuser is not locally saved.

Corry Armar  +256 776 653 528 or +250 789 523 060

On Tuesday, May 21, 2019, 7:58:33 PM GMT+3, Adam Chelminski <notifications@github.com> wrote:  

Okay, try using this file:

https://gist.github.com/adamchel/6976979294e5a59c255e588ebdddfd8e

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ArmarJosh commented 5 years ago

Hi Adam,Please ignore my previous email...Since AnonymousLogin was handling saving client to async i thought that behavior would persist. i realized i had to handle that myself.Please note the RNCommunityAsynStorage script works  like a charm. However i have a second issues i need you guidance on.How do i handle getting of tokens and tokenId when the user verifies the email in react native.The documentation shows how to do it in the browser. But how do i handle that in my React Native app. Thanxs Again. Corry Armar  +256 776 653 528 or +250 789 523 060

On Wednesday, May 22, 2019, 2:42:40 PM GMT+3, Corry Armar <armarc02@yahoo.com> wrote:  

Hi Adam, Thanks a lot for this. it works.Though i have anew issue.. Not sure if its me doing something wrong, But when one logs in with passwordCreditals, and the app is refreshed the user is not remembered. it goes back to the login screen every-time.looks like the authuser is not locally saved.

Corry Armar  +256 776 653 528 or +250 789 523 060

On Tuesday, May 21, 2019, 7:58:33 PM GMT+3, Adam Chelminski <notifications@github.com> wrote:  

Okay, try using this file:

https://gist.github.com/adamchel/6976979294e5a59c255e588ebdddfd8e

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

adamchel commented 5 years ago

Hi @ArmarJosh, apologies for the late response.

You have two options here,

The easiest would be to host a simple browser application that can be handled by the user in a mobile browser session. See https://github.com/adamchel/stitch-email-conf-util for a sample application that can support the confirmation flow. In this flow, you would want to direct users back to your app after the confirmation is complete.

If you want a native way to handle the links, you'll need to set up deep linking to handle your confirmation URL, which requires you to have native code (so you must have ejected from Expo). See https://facebook.github.io/react-native/docs/linking for an explanation of how to do deep linking with React Native.

Let me know if you have any other questions.

pedro-lb commented 5 years ago

I'm also having this problem where I get warnings because Async Storage is not installed from react-native-async-storage.

I tried @adamchel 's solution as described below and I get no errors, but persistent storage doesn't work.

Stitch.initializeAppClient( "your-client-app-id", new StitchAppClientConfiguration.Builder() .withStorage(new RNCommunityAsyncStorage()) .build() );

adamchel commented 5 years ago

@pedro-lb can you clarify what issue you're seeing? Is the storage not persisting between app restarts?

pedro-lb commented 5 years ago

@pedro-lb can you clarify what issue you're seeing? Is the storage not persisting between app restarts?

Exactly. No warnings appear, but the storage does not persist between app restarts.

adamchel commented 5 years ago

Are you seeing this with your final app, or just in Expo/in development? Is it possible that Expo or your development environment is clearing persisted storage between app restarts?

ArmarJosh commented 5 years ago

Hi Adam.This is as issue with the wrapper class u shared. The wrapper eliminates the async storage warning. But the login doesn’t persist. The moment the app is closed on reopen u have to sign in again. Am using the react native Cli. 

Sent from Yahoo Mail for iPhone

On Monday, July 15, 2019, 2:48 PM, Adam Chelminski notifications@github.com wrote:

Are you seeing this with your final app, or just in Expo/in development? Is it possible that Expo or your development environment is clearing persisted storage between app restarts?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

pedro-lb commented 5 years ago

Are you seeing this with your final app, or just in Expo/in development? Is it possible that Expo or your development environment is clearing persisted storage between app restarts?

In development, but the app is not no expo. I don't think that the issue is related to anything beyond this library clearing the cache, since it works normally without the async storage (albeit showing the warning).

mzablocki commented 5 years ago

Hi, does anyone have solution to this problem? Currently if I start new pure RN app and use mongodb-stitch-react-native-sdk it fails on start due to AsyncStorage issue. I tried multiple things and end up with either AsyncStorage warning/fail or I am loosing Stitch session between app restarts.

wgarrido commented 5 years ago

Same problem. I can’t update my react-native app to 0.61. When will you update Stitch SDK to be compatible with the latest version of react-native ? It's a big blocker ... SDK for react-native still alive?

Begoodi commented 4 years ago

Any news on update to be able to use react-native-community/react-native-async-storage ?