Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can mobx-persist be used with react-native-keychain or a similar storage container? #86

Open
knakamura13 opened this issue Apr 20, 2020 · 1 comment

Comments

@knakamura13
Copy link

According to the docs, mobx-persist can only store data in AsyncStorage, localStorage, and LocalForge.

However, is there any way to make mobx-persist work with a different storage container, such as react-native-keychain, to allow for encrypted storage?

I'm looking for a secure method for persisting passwords, tokens, cookies, etc. on iOS and Android, while still using Mobx.

@DjamshidDjurayev
Copy link

DjamshidDjurayev commented Oct 14, 2020

Yes. You can create new class secureStorage, implement functions (getItem, setItem, removeItem) and pass it instead of async storage

I'm using react-native-sensitive-info, you can use whatever you want

import SInfo from 'react-native-sensitive-info';

export const setItem = (key: string, value: string) => {
  return new Promise(async (resolve, reject) => {
    try {
      await SInfo.setItem(key, value, options);
      resolve(null);
    } catch (e) {
      reject(e);
    }
  });
};

export const getItem = (key: string) => {
  return new Promise(async (resolve, reject) => {
    try {
      const result = await SInfo.getItem(key, options);
      resolve(result);
    } catch (e) {
      reject(e);
    }
  });
};

export function removeItem(key: string) {
  return new Promise(async (resolve, reject) => {
    try {
      await SInfo.deleteItem(key, options);
      resolve(null);
    } catch (err) {
      reject(err);
    }
  });
}

import * as SecureStorage from 'your-secure-storage';

const hydrate = create({
  storage: SecureStorage,
  jsonify: true,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants