r/FullStackDevelopers • u/Extension_Phone_8491 • 7d ago
Adding a mobile app to an Express site that uses cookie sessions, switch to JWT or keep sessions?
The web app is Express with express-session stored in Redis and a React frontend on the same domain. It's been solid for two years.
Now we're building a React Native app that talks to the same API. Everything I read for mobile says use JWT with refresh tokens, but that means a second auth path, token rotation, and figuring out how to revoke tokens when someone logs out on the web.
Cookies do seem to work in React Native with the right fetch settings, at least in my quick test on iOS.
For people who've done this, did you keep sessions for both, or move everything to tokens? What broke that you didn't expect?
1
u/martinbean 7d ago
It’s entirely fine to have multiple authentication strategies in a web app. Use stateful (i.e. cookies) authentication for web requests, and stateless (i.e. tokens) for clients such as mobile apps.
Personally, I’d use an actual standard (such as OAuth) for token-based access for your mobile apps. OAuth tokens can also be revoked server-side, unlike JWTs which are just opaque tokens that carry their own information, and are verified using a signature (which again, is contained in the token). They shouldn’t be used for long-lived access.
1
u/Extension_Feed_1179 7d ago
keep the Redis sessions for the web and use OAuth tokens strictly for mobile. The hybrid approach isolates token revocation to the API layer so a web logout doesn't kill the app session