skip to Main Content

I have a web app that communicates with an auth server that stores the access & refresh token in an httpOnly cookie when the user logs in, now building an app so what is the best practice for storing those tokens in React-Native (I am using bare react native not expo), I have microservices architecture so what more recommended to create a auth server for the app? or to add more controllers, routes, services in the existing auth server?

2

Answers


  1. Use React Native Token Storage

    Best Practices include
    Utilizing secure storage methods in React Native for token storage. Options such as AsyncStorage, SecureStore (Expo), and encrypted storage libraries provide better security for sensitive data like tokens. Avoid using AsyncStorage alone for storing tokens to ensure data is not stored in plain text.

    Handling Tokens and Authentication in Microservices Architecture
    which you already using by using auth and refreshing a token.

    referances:
    A Bullet-Proof Approach to Storing Sensitive User Data in React Native, Is React Native’s Async Storage secure?, Safeguarding Your Data in React Native: Secure Storage Solutions, OWASP JWT cheatsheet, JWT Best Practice, How JWT is reliable?, JWT secure approach to web app

    Login or Signup to reply.
  2. I would recommend to use react-native-mmkv with zustand.
    Also you can persist it using a middleware.

    https://github.com/mrousavy/react-native-mmkv/blob/main/docs/WRAPPER_ZUSTAND_PERSIST_MIDDLEWARE.md

    import { StateStorage } from 'zustand/middleware'
    import { MMKV } from 'react-native-mmkv'
    
    const storage = new MMKV()
    
    const zustandStorage: StateStorage = {
      setItem: (name, value) => {
        return storage.set(name, value)
      },
      getItem: (name) => {
        const value = storage.getString(name)
        return value ?? null
      },
      removeItem: (name) => {
        return storage.delete(name)
      },
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search