Next.js Discord

Discord Forum

set cookies on page

Unanswered
Headless posted this in #help-forum
Open in Discord
I am building a auth and it will use server sessions + jwt.

The JWT basically is just a carbon copy of the session on the server. I basically want to keep these two in sync. Whenever I try to access the JWT and there is no token or its invalid, I want to first get the session and build another JWT and set the cookies for it if the server session is alive and real.

My problem is I want this to all be automated for me and be done in the getCurrentSession() function. My issue is that cookies can't be set unless its in a route handler or server action. Whats the best way about doing this or if theres something else I should look into please advise.

2 Replies

if getCurrentSession() is null ill probably redirect to the login page, however getCurrentSession() ideall should return the JWT session and if it does not it should create a new JWT and set the cookies for it