Getting localStorage from Ionic application in my React Native app - react-native

We are rebuilding an Ionic 1.x application with React Native. The app is used by a lot of people and I don't want everyone to log in again after they update the app.
The current app uses localStorage to save the token that defines if a user is logged in (I know, it's not the safest method). Is there a possibility that we can get the current token from the localStorage in React Native and put in our secure storage?
So basically can we call the localStorage instance in React Native? We are using the same bundle identifier so many there is a possibility to access the localStorage from the old app.

You wont treat with a web enviroment like Ionic, then localStorage wont exist, but you can use AsyncStorage instead in react native or some DB like sqlite, realm, whatermelonDB (the last one I didnt use) to save your user data

Related

Setting the User Context App Insights for React Native

We have a React Native app and we are logging to App Insights using the "applicationinsights-react-native package", this all works fine in a sense, but we are trying to start using the monitoring side of things which uses a User ID. Now I'm pretty sure that whatever the User ID that the (app insights) package is using for a user ID won't cause too many problems if we kept it, but it won't be right.
The ApplicationInsights class has a setAuthenticatedUserContext method, however the comments seem to refer to cookies suggesting it's a React package re-purposed and this GitHub post https://github.com/microsoft/appcenter-sdk-react-native/issues/503 suggests we can't use it, however the response is for the React Natve AppCenter package which we are not using. We are using App Insights direct.
So I was wondering if there was a way to set our user_Id/User context if we are using App Insights directly from a React Native app?
It looks like setAuthenticatedUserContext does work if you talk to App Insights directly and not theough Appcenter, it's possible that it works through Appcenter now as well, I have not tested so I am not sure.
If you want to check that this ends up as on the App Insighst side, it appears as a property called user_AuthenticatedId.

How to connect my react native app to existing database using Amplify?

I have react native app that already at the store.
I decided to move my database and my frontend and backend using Amplify.
I would like to connect my react native app using Amplify too, my needs are to check if user is sign in and get access token, refresh token, token expired date, sign out and using the different apis on the backend to get data...
I was looking on different documents like this one but couldn't find a way to connect to exist one, the only option I have seen is to create a new database only for the mobile...
What are my options? I thought maybe I should create login and refreshToken functions in the backend and only call those functions every time I need to log in or refresh a token... or maybe I should use configuration file somewhere? I was thinking about this file awsExports but not sure this is the right one, there's no explanation about it
Thanks in advance

Migrating a native app to a RN/Expo app: keep user authenticated

I want to migrate an existing Android+iOS native app to a react-native Expo app.
In current native app, we store an auth token. I'd like this auth token to be available through ReactNative AsyncStorage api out of the box, without requiring RN native code (ie, ejecting Expo).
Is this possible, in current native app, to start writing to the same place as AsyncStorage will read after the migration?
We aim for the smoothest transition from native app to RN app, and user should stay authenticated after the upgrade.
Depends on what you're current app is using for storage. I recently used this library (https://github.com/kevinresol/react-native-default-preference) to get the data from user defaults then move it into async storage. I only migrate the refresh token and auth token.
If they are using core data, then you'll need to setup the same models etc - https://github.com/realm/realm-js/issues/584
The other storage mechanisms you can easily find a native package to get the data.
if the app is under same app name scheme you may be able to access after upgrade i guess.

Possible to access Cookies in a WebView in React Native?

If you create a WebView within a react-native application, is it possible to access the cookie from the WebView to be passed in subsequent requests?
An example would be presenting the User with a login page with reCaptcha in a WebView. Then using the authentication cookies from a successful login to make subsequent API requests to the same site.
React Native is just a bridge on top of the native code. Anything you can write in objective-c/java can be used in React Native by creating native modules.
I am not sure if there is JavaScript code present for clearing the cache of a webview, but you can certainly write native code for it and then bridge it using native module.
Here is the link for the native code(iOS) : https://stackoverflow.com/a/5606703/2164029
Tutorial for creating native moduels : https://facebook.github.io/react-native/docs/native-modules-ios.html
I believe this https://github.com/joeferraro/react-native-cookies should provide you what you want.I have used this to clear cookies successfully.

What is the recommended way to store secret tokens in a react native app?

What is the most secure and the recommended way to store things like access tokens in a react native app? Shall I store them in the android shared preferences, in the redux store or AsyncStorage?