How to manipulate JSON files without react-native-fs?

So, I am working on an application that should work as a menu for a restaurant. I need to keep some data offline and available all the time (like the restaurant the user is in, the user login, etc). I decided to keep a JSON file for this, but I can’t seem to manipulate it, because expo isn’t supporting react-native-fs which I was going to use. Is there an alternative to it?

If there isn’t, what would be a good idea to keep those values offline?

  • FileSystem (https://docs.expo.io/versions/latest/sdk/filesystem/) - not quite as much control as react-native-fs, but should be fine for caching if you have to be manipulating discrete files
  • AsyncStorage (https://docs.expo.io/versions/latest/react-native/asyncstorage/#__next) - Doesn’t storage JSON files, but stores JSON structures, which should be fine for caching data that exists online for offline use. If you’re ready to stuff it into a JSON file, I don’t see why you can’t instead stuff that JSON into an AsyncStorage key.
  • SecureStore (https://docs.expo.io/versions/latest/sdk/securestore/#__next) for login credentials if you absolutely have to store actual login credentials. In any relatively modern API, there really is no reason you should need to store login credentials, so if you are, do reconsider that. If you’re just looking to store a session token, strictly speaking that isn’t a “must use SecureStore” scenario IMO, but I guess it doesn’t hurt, especially if tokens are longer-lived and could do some damage if leaked.

Thanks for the answer. I’ll check these out right away. I have a question though, if I shouldn’t store the login credentials, how else can I make the app maintain logged in the same user?

Session cookies, JWT’s, or some other token. You log into your API, you get a token back, that can be passed with each subsequent request. That token is what you store in local storage. Any recent and credible backend framework will either have session or stateless token security (more likely, both) built-in or available as a plugin. Use the standard framework- rolling your own security is more work and much less secure than the widely-available alternatives.

In case you could use a primer on some best-in-class ways to secure your app… you have to pay for this (or start a free trial), I haven’t watched it yet, and it’s for web, but Cory is an amazing teacher and I bet the content translates well enough to RN: https://www.pluralsight.com/courses/react-auth0-authentication-security