NuxtN
Nuxt14mo ago
5 replies
Tony

useCookie bugged, not keeping state

I am trying to build a system to keep track of user auth, using composables and
useCookie
. It works fine however the cookie is completely forgetting its
token
value between functions.

Here's the code: https://pastebin.com/UiRnSPRc
When the user calls
logIn
, the token is fetched and set to the cookie. At line 47 you can see I'm logging it and in my tests it is set to the correct value. However the
logIn
function then calls
fetchUser
, which accesses the same cookie - but on line 74 you can see it logs
undefined
for some reason.

The cookies are both the same, to ensure it I defined a custom
useTokenCookie
. I'm really not sure what's happening and why the cookie just magically forgets it's set value?
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Was this page helpful?