Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store private data in react-native?

How can i implement feature like remember me when authenticating via react application? I think unencrypted AsyncStorage isn't the best way to do it, because data is open for users. I've tried to use realm, but stuck into problem that cannot be resolved in android using expo to test application. It says that i need to compile native code for android and edit that (Add realm object creation in MainApplication.js). I don't want to compile my project while it's not released yet. How does instagram and the other RN-apps store authentication data? What is the best approach?

like image 515
IC_ Avatar asked Aug 07 '17 13:08

IC_


People also ask

Is Async storage safe React Native?

According to official RN docs, AsyncStorage is an asynchronous and unencrypted key-value store. Because it is unencrypted, nothing persisted in AsyncStorage should be considered as secured. Android: AsyncStorage uses the database to save the data (either RocksDB or SQLite).

What are the two ways to handle data in React Native?

There are two types of data that control a component in React Native: props and state. For data that is going to change in the future, we use state. The state contains the data or information about the component.

Is Async storage safe?

Async Storage is great but it lacks security. This is less than ideal when storing sensitive data such as access tokens, payment information and so on. This module aims to solve this problem by providing a wrapper around Android's EncryptedSharedPreferences and iOS' Keychain , complete with support for TypeScript.


2 Answers

What is the best way to store private data in react-native?

I would recommend using a library like react-native-keychain to store private data in react-native

You can use it like that:

// Generic Password, service argument optional
Keychain
  .setGenericPassword(username, password)
  .then(function() {
    console.log('Credentials saved successfully!');
  });

// service argument optional
Keychain
  .getGenericPassword()
  .then(function(credentials) {
    console.log('Credentials successfully loaded for user ' + credentials.username);
  }).catch(function(error) {
    console.log('Keychain couldn\'t be accessed! Maybe no value set?', error);
  });

I hope my answer was helpful 😊

like image 161
Julien Kode Avatar answered Oct 02 '22 03:10

Julien Kode


Expo.SecureStore provides a way to encrypt and securely store key–value pairs locally on the device.

Use SecureStore.setItemAsync(key, value, options) to store and SecureStore.getItemAsync(key, options) to retrieve data.

Documentation: https://docs.expo.io/versions/latest/sdk/securestore

like image 28
pyankoff Avatar answered Oct 02 '22 03:10

pyankoff