Using Flask Session with next js

202 Views Asked by At

I am trying to fetch user/session-specific data in a server component. If the user doesn't have a session, flask-session will automatically create a session and return the session id as a cookie, but as far as I'm aware you can't set cookies in server components.

My current solution is to use a middleware that checks if the user has a session cookie, and if they don't, send a request to the api to start a session and set the cookie manually. The problem with that is that if the user happened to not use anything that requires a client component to send a request, the cookie will expire while they are actively using the app.

Is there a better solution? What should I do?

0

There are 0 best solutions below