NuxtN
Nuxt2y ago
3 replies
Gobbo

useCookie empty on client?

I'm using useCookie with universal rendering.

However, when I try to access my cookie client side, it appears to be undefined however, SSR shows the cookie is there but then gets unset after?

Not sure why this is, here is my code and my cookie, this is all inside app.vue

<script setup lang="ts">
const auth = useAuthStore();
const cookie = useCookie<string>('vault.sid', { readonly: true });

console.log(cookie.value)

onMounted(() => {
  // Lets check for the existence of our cookie :)

  if (!auth.isLoggedIn) {
    console.log(cookie.value)

    if (!cookie.value) return;

    auth.checkForToken(cookie.value);
  }
})

</script>

<template>
  <div>
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </div>
</template>
image.png
image.png
Was this page helpful?