Next.js Discord

Discord Forum

Should I handle user sessions client or serverside?

Unanswered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
In my project I am currently using firebase for authentication and they have a client side api I can use to keep track of the current user, however I want to make this website very interactive where information about the user is being written and read to frequently. I also know that in the nextjs docs they specify using useEffect for fetching and updating data is not recommended and always try and fetch data server side if possible. What is the best way to deal with this? I assume this is a common problem so what are some ways you all have dealt with this?

4 Replies

Eulophid wasp
not an expert but i recently used firebase for a related task
(SSR):
Use Firebase's Firestore to establish a real-time connection on the server-side.  
Pass the initial user data (for its just auth tokens and some of the analytics data)
Client-Side Real-time Updates:

On the client-side, use Firebase's client-side SDK (real-time)
Listen for real-time updates to the user's data (e.g., using onSnapshot in Firestore).
Update the user data in your application state accordingly.
also using gemini on the firebase console was a big help in navigating and understanding.
Eulophid wasp
for managing the user state.