Unlock the Power of Encrypted Local Storage in React Native

When it comes to storing data locally in React Native, AsyncStorage is often the go-to solution. But what if you need to store sensitive information, like a JWT token? That’s where things get tricky. AsyncStorage is unencrypted, which means anyone with access can read your data – not ideal for sensitive info.

The Risks of AsyncStorage

Imagine storing a user’s theme setting or allowing them to pick up where they left off after restarting their phone or app. That’s exactly what AsyncStorage does – but at a cost. The data you save with AsyncStorage is unencrypted, making it vulnerable to prying eyes.

Enter Encrypted Data Storage Alternatives

For sensitive information, you need an encrypted and secure way of storing data locally. Luckily, there are options:

  • react-native-keychain
  • react-native-sensitive-info
  • expo-secure-store

In this article, we’ll dive into Expo SecureStore, a powerful and secure solution for storing sensitive data.

Getting Started with Expo SecureStore

To create a React Native project, simply paste the following command into your Terminal:

npx react-native init MyProject --template react-native-template-typescript

This will create a new React Native project with a TypeScript template. Now, let’s build the app and see it in action!

Configuring Expo SecureStore for iOS

If you’re adding unimodules to an existing project, pay close attention to where you delete and add new lines of code. Make sure to update your AppDelegate.h, AppDelegate.m, and Podfile accordingly.

Configuring Expo SecureStore for Android

Update your android/build.gradle, android/app/build.gradle, and android/settings.gradle files to get started with Expo SecureStore on Android.

Exploring the Expo SecureStore API

SecureStore has three main API methods: set, get, and delete. Let’s explore them in our App.tsx file. Replace the contents with:
“`
import React, { useState } from ‘eact’;
import { View, Button, Text } from ‘eact-native’;
import { SecureStore } from ‘expo-secure-store’;

enum Key {
TOKEN,
}

const App = () => {
const [token, setToken] = useState(”);

return (

Leave a Reply

Your email address will not be published. Required fields are marked *