NuxtN
Nuxtβ€’16mo ago
YuliyaMinsk

Cookies not updating on h3 server in Nuxt 3

Could you please help me understand why cookies aren't being updated on the h3 server?

I created an endpoint:
server/api/auth/refresh.ts

I retrieve the cookie and log it to the console, everything seems fine:

const encryptedAccessToken = getCookie(event, 'access_token');
console.log('AccessToken', decryptValue(encryptedAccessToken));


Then, I delete it:

deleteCookie(event, 'access_token');


But when I try to retrieve it again, it still returns and logs the old version 😭:

const encryptedAccessToken2 = getCookie(event, 'access_token');
console.log('AccessToken', decryptValue(encryptedAccessToken2));


Then, I try to replace its value:

const newEncryptedAccessToken = encryptValue(access_token);
setCookie(event, 'access_token', newEncryptedAccessToken, {
  httpOnly: true,
  secure: isProduction,
  sameSite: 'lax',
  path: '/',
  maxAge: 60, // 1 minute
});


But when I try to retrieve it again, it still returns and logs the old version πŸ˜†:

const encryptedAccessToken3 = getCookie(event, 'access_token');
console.log('AccessToken', decryptValue(encryptedAccessToken3));


I tried adding a delay and using await (even though these functions are not async according to h3 cookie examples), but nothing seems to help.

What could be the issue?
Was this page helpful?