`useSession()` unexpectedly changing
I'm having a hard time with
useSession()
and I'm not sure how to articulate my issue. I have some routes protected by a getAdmin()
query, redirecting the visitor if is not logged and not admin. The process is working, and the session is supposed to be valid for 14 days. However, after 1 click, or after n clicks – it varies, it does not work anymore.
I noticed in the request header in my browser that the cookie value is changing when it happens: from cockpit=Fe26.2**78859073ec...
(the valid/logged cookie) to cockpit=Fe26.2**1be0589ce4be
(the invalid/blank cookie) without specific reasons.
What I noticed though is that the cookie is changing due to the response of the admin layout route as shown in the screenshot.1 Reply
The relevant code snippets are the following:
I suspect the issue comes from the fact getAdmin() is called at two different places in the AdminLayout(), and that there is some kind of unsync at some point where useSession() does not take into account the cookie from the request, and therefore reply with a different cookie (like the default session created by h3)
I'm having a hard time figuring out how to solve that..