NuxtN
Nuxt16mo ago
YuliyaMinsk

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!
Was this page helpful?