Can't having Usefetch working with Session/Cookies on SERVER SIDE ONLY (using laravel sanctum api)
Hello
How can I have usefetch working perfectly with Session/Cookies on SERVER SIDE ONLY using laravel sanctum api.
It works perfectly if my middleware is client side (if process.client) but doesn't work anymore if my middleware if server side only (process.server)
If i'm using nuxt server side only Laravel is returning me this :
CSRF token mismatch.
Here my middleware
15 Replies
useSanctumFetch.ts
Nuxt .env
nuxt.config.ts
On my laravel .env I have :
cors.php (into laravel sanctum)
What's wrong ? Why if i'm server side with nuxt it doesn't work anymore ? I tried everything since multiple days but can't fix that.
so on server side you probably don't get the cookie
that's probably what's causing the issue
you can put your tokens on the pinia store and persist it
pinia will share those tokens using cookies between client and the server
might help
That is what I'm doing but it doesn't work. I don't know why..... it's like sanctum laravel api doesn't accept my server request
I have a cookie; but didn't match when i call back my api
and on the client side, works perfectly
the cookie is set when making request to /sanctum/csrf-cookie?
Yes right
I'm not sure but can you use
useAsyncData
there?
it might be used only inside script setup but i'm not sureI could but never used that I don't know how to do that atm
I can try
useAsyncData
shared the result between client & server so it might worknot usefetch ?
usefetch uses useAsyncData under the hood
So usefetch should work ?
yeah
didnt work with useAsyncData
Laravel use TOKEN + session cookie and I don't know how to get these cookies from my server side. it's like session cookie doesnt exist on my nuxt server side
same issue as him atm
did you manage to find a solution here?