set cookies on page
Unanswered
Headless posted this in #help-forum
HeadlessOP
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.
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
HeadlessOP
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
@Headless 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.
You can create a route handler for updating and setting the fresh jwt to the cookies (this happen on server)
Then whenever getCurrentSession() is called, you first have to check if that jwt is still valid or not. If it is invalid you can fetch the route handler that you made before, so it create a cookie with fresh jwt data.
Then whenever getCurrentSession() is called, you first have to check if that jwt is still valid or not. If it is invalid you can fetch the route handler that you made before, so it create a cookie with fresh jwt data.