5

I am building two react native apps where i need to keep few things in common like username(login) and few other information.I tried to store using AsyncStorage (React Native Storage) and everything was working but now i need to use one common data base for both the apps as the user login success in first app then the other app should also be logged in.As Asyncstorage cannot be used in this case any other option in react native.

USE CASE FLOW

anbu selvan
  • 725
  • 3
  • 13
  • 41
  • can you explain your use-case a bit more? – Aseem Upadhyay Sep 18 '18 at 10:30
  • the use case is simple when user signs on first app then when user opens second app then this should already be logged in using the credentials info from the other app.So to avoid multiple times sign in procedure. I understand the security risk here but since both apps belong to same organisation this will be easier for user instead of multiple sign in. – anbu selvan Sep 18 '18 at 10:44

3 Answers3

3

The new privacy laws do not let share the same database for 2 applications. The only thing you can do is put the database online and access to it by both apps. At least it happen in Europe. Anyway you can't use the same AsyncStorage to 2 different apps. See more here: https://stackoverflow.com/a/48806319/8898886

SmoggeR_js
  • 2,950
  • 4
  • 22
  • 52
  • thanks but i know it cannot be achieved thorugh AsyncStorage or Realm Database but there should be a way.Is content provider as in android docs [here](https://developer.android.com/guide/topics/providers/content-providers) can be used ? – anbu selvan Sep 18 '18 at 10:45
  • I think there is not a way to do it. Anyway, as I told before, the only idea I have is make online your database and call ir from the both apps. If you find a way don't doubt to post it here. – SmoggeR_js Sep 18 '18 at 10:49
2

In Android, the system design do not permit that. Every app has its own sandbox. Shortly, an app can not access the database of another app.

But it could be swindled, at your risk.

You could use a sqlite database, put the database file in a shared directory, and access that file from each app. Please note that each means really each. Every app on the device could access that file, so it is not a safe place for sensible data.

The best solution, as proposed, is to use a external db, accessible from the network, to store your data. If you belive that the effort is not worth it, you could use Firebase, for example.

Andriy Klitsuk
  • 564
  • 3
  • 14
1

You can not use that locally. But with Firebase you can make 2 app have same Firebase Realtime database so you can share data between 2 app (event realtime). I prefer use this react-native-firebase library for React Native https://github.com/invertase/react-native-firebase

Tung Duong
  • 1,156
  • 7
  • 19
  • I'm already using react native firebase, so are you mean to put the google package.json(contained api key , package name , etc ) in the two app files ? – DevAS Apr 20 '19 at 22:17