r/reactnative • u/ConfidentWafer5228 • 13d ago
Help Web Auth equivalent of JWT+Sessions in react native
I have been using JWT accessToken (short lived token stored in memory ) as normal js variable/react-state + a long lived refreshToken/sessionCookie in httpOnly secure cookie for all my custom auth websites with a express backend and plain react frontend.
Wanted to get started with react-native + expo project But i have no idea on how to implement secure custom auth. Pretty sure cookies are not a thing on mobiles, so had this doubt. Don't know if localStorage is safe.
What is the standard way to handle this? Could anyone please even just give some doc link or tell what to search, cuz i can't find appropriate material to study ( also pls dont tell to ask AI )
2
u/Western_Cap_6934 13d ago
You can keep the short-lived access token in memory. For the persistent refresh token, look up Expo SecureStore rather than localStorage or AsyncStorage. Expo documents secure storage in its authentication guide. SecureStore handles local storage, while your backend still needs to validate and revoke sessions.
1
u/syedaalishan 13d ago
For your follow-up about one controller: share the session creation/validation logic, then give web and mobile different ways to carry the token. The web client can keep using its cookie; the native client can send an access token in the Authorization header. Refresh and logout should still go through the same backend session rules. Keep the cookie-based web endpoints' CSRF checks in place when adding the mobile path.
1
u/MeasurementGreat5273 13d ago
no cookies needed. keep the refresh token in expo-secure-store (keychain/keystore), access token in memory like you do now. localStorage equivalent is AsyncStorage and that's not encrypted. docs: https://docs.expo.dev/versions/latest/sdk/securestore/
0
u/[deleted] 13d ago
[removed] — view removed comment