Middleware http-only cookies validation
Hi! I am trying to validate cookies on my middleware following an http-only cookies authentication strategy to restrict access to certain routes for authenticated users. For non-authenticated users it works perfect but for authenticated users, if they directly type the url or reload the page when in a protected route, as cookies are http-only it doesn't send them and navigates to '/'. If i use useFetch with server: false, it does not interrupt navigation to the page itself for unauthenticated users, it denies access but once on the route, crashing the page. Also tried this, which results on hydration conflicts:
current middleware:
/middleware/auth.global.js
thanks in advance!2 Replies
https://nuxt.com/docs/getting-started/data-fetching#passing-headers-and-cookies
The
$fetch
/ useFetch
does send internal requests in SSR. Maybe you can pass the header/cookie as needed.Nuxt
Data fetching · Get Started with Nuxt
Nuxt provides composables to handle data fetching within your application.
thank you sooo much it was as easy as