react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.61k stars 459 forks source link

@react-native-async-storage/secure-async-storage #1053

Closed slavko-lukic closed 5 months ago

slavko-lukic commented 5 months ago

Proposal

I understand this was discussed before but one thing I see missing from react native is providing simple and clear way to securely store data. This would pretty much resolve the question best way to store tokens in react native?. This package would work the same way as it does now but it would have extra step to encrypt data before storing it and decrypt after reading it. There is react-native-keychain that can do that but it's interface could be confusing to some people and looks like that it has specific use case, it persist data between reinstalls etc...

This package would live in separate context from AsyncStorage so SecureAsyncStorage.getItem('my-key') and AsyncStorage.getItem('my-key') would return different values potentially. I am not much of a native developer so I will not go into that part but for javascript part I am proposing simple interface like AsyncStorage already has:

import SecureAsyncStorage from '@react-native-async-storage/secure-async-storage';

const storeData = async (value) => {
  try {
    await SecureAsyncStorage.setItem('my-key', value);
  } catch (e) {
    // saving error
  }
};

const getData = async () => {
  try {
    const value = await SecureAsyncStorage.getItem('my-key');
    if (value !== null) {
      // value previously stored
    }
  } catch (e) {
    // error reading value
  }
};

Would something like this be possible?

Alternatives

No response

Implementation Details

No response

Additional Context

No response

krizzu commented 5 months ago

Hey @slavko-lukic, thanks for putting this together.

Actually, this is our end goal for next major version - different types of storage, accessible via same, simple API. This would allow to cover different use cases, such as mentioned, secure storage. I'm finishing up sqlite rewrite of storage, but due to time limit, it's dragging out a bit.

We already have API prepared for different storages to apply it, so that's that πŸ˜„

slavko-lukic commented 5 months ago

@krizzu It's good to know that this is in the works. It's gonna be really good for the community! πŸ˜†