Hi, I have a backend using C# for my next.js app.
I want to implement a login and dont really know how to store the jwt token and the user data i get from the backend. Is it a good way to store this data in the localstorage?
I have already tried using next-auth but its not really usable in my case.
I also tried to work with zustand but the data get lost after refreshing the page so its not really usefull.
How do you guys handle this?
#handle login
9 messages · Page 1 of 1 (latest)
add: i cant really use next-auth cause i have to save data (User can upload some data) and i dont get a userid from response. Also im using mssql and there is no direct adapters from next-auth.
Really, it sounds like storing the token and the user in localStorage is your best bet
And maybe look into refresh tokens stored in cookies
What I've done sometimes is store token/user in LocalStorage but also in global state, so marry those two together then you can check if one exists or not
Using JWT for auth is already questionable (best to use simple sessions). See https://redis.com/blog/json-web-tokens-jwt-are-dangerous-for-user-sessions/
Is it a good way to store this data in the localstorage?
Nope since local storage is exposed to the client. Your less worse bet here would be on cookies with httpOnly