YuliyaMinsk
YuliyaMinsk
NNuxt
Created by YuliyaMinsk on 9/10/2024 in #❓・help
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));
const encryptedAccessToken = getCookie(event, 'access_token');
console.log('AccessToken', decryptValue(encryptedAccessToken));
Then, I delete it:
deleteCookie(event, 'access_token');
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));
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
});
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));
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?
1 replies
NNuxt
Created by YuliyaMinsk on 8/27/2024 in #❓・help
Best Practices for Nuxt 3 + JWT + Pinia + TanStack Query Integration
Hi everyone! I need some help with organizing a Nuxt 3 project that uses JWT, Pinia, and TanStack Query. My current setup: - On the login page, I send a request through TanStack Query with the entered phone number and password. - The received tokens (access and refresh) are encrypted and stored in cookies via Server Routes, and also saved in Pinia. However, I realize this might not be the best approach. I have a few questions: - Should I be using Pinia and TanStack Query for this? - Would it be better to send the phone number and password directly to Server Routes, make a secure request to the backend from there, encrypt the tokens, and store them in cookies? Then, use middleware to check route protection and user login status by making requests to Server Routes. - I'm also considering adding an extra request to Server Routes in useCustomFetch to verify login status and refresh tokens if needed. I'm planning to handle 401 errors and logouts in Server Routes as well. Can you please advise on the best way to organize this process? I'm a bit confused and would really appreciate some guidance!
18 replies