How should I store session / user data on client
Hey, so how should I store session / user data on the client? So I know that I can retreive the full session and user object from my authClient with useSession() or I can setup and endpoint like /api/me and fetch the objects from my API.
But should I fetch them just one time on signIn for example and keep these objects in my local storage or cookies and delete them when the user logs out or just fetch them anytime I need them? For example for Username, Image in a Navbar or something like this I hope my point is clear
Just for reference, currently using a vite vue app for frontend and express.js for backend
(I would also be open to completely switch to a fullstack framework like next.js if anybody would advise me to, I'm just familiar with vite and vue thats why I chose this)
Sorry if it's a stupid question, I'm new to web development
Solution:Jump to solution
I generally save to state on hard reload and read on soft reload /navigation and obviously protect all api routes so that if user does get logged out - no sensitive data will be returned. Obviously also put all important data in api. Not a stupid question! A great question!
4 Replies
Solution
I generally save to state on hard reload and read on soft reload /navigation and obviously protect all api routes so that if user does get logged out - no sensitive data will be returned. Obviously also put all important data in api. Not a stupid question! A great question!
So you can use pinia or some of the vue use stuff
Thank you 😄
Guess I'll have a look into pinia now
Just to be sure, with hard reload you mean refreshing the page, quit and reopen the browser, and things like that and soft reload router navigation, where the site doesnt reload completely right?
yes