Laravel/Sanctum user fetch #1699
-
Hi! I'm trying to create an SPA for a laravel REST API protected by Sanctum Right now, on my SPA the user can log in without a problem and the API sends back the token; but then the SPA doesn't fetch the user. I mean, it doesn't even try to fetch it; no error, no request, no nothing. Login and logout work flawlessly, but I'm unable to fetch the user. Here's my config for auth module ( v5 ):
My login function. If I understand correctly, just by login the laravel/sanctum provider should fetch the user data:
My logout function, just for completion ( it shouldn't have anything to do with the problem ):
Out of despair, I even created a function to try to fetch the user manually 😅 :
On login, everything's fine but there is no request to the user endpoint: When I try to fetch it manually, there is no request either: And then on logout, everything works as it should: If it made the request to the /user endpoint ( either automatically after login, or manually when I use the fetch function ) and the API rejected it I would have something to work with ( I'm in control of the API too ), but with no request I just don't know where to start debugging the problem. Could anyone help me? I have some cookies I can share 🍪 🍪 🍪 🍪 🍪 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Just a friendly bump :) |
Beta Was this translation helpful? Give feedback.
-
Hi everyone! Just passing by to say I could finally solve the problem! Yay! 🥳 There was no request to /user because there was no XSRF-TOKEN cookie. And there was no XSRF-TOKEN because of browser security. Long story short, this solution worked for me -> #1164 (comment) I hope this is helpful for anyone on the same situation :) |
Beta Was this translation helpful? Give feedback.
Hi everyone!
Just passing by to say I could finally solve the problem! Yay! 🥳
There was no request to /user because there was no XSRF-TOKEN cookie. And there was no XSRF-TOKEN because of browser security.
Long story short, this solution worked for me -> #1164 (comment)
I hope this is helpful for anyone on the same situation :)