margungijs's avatar

Laravel sanctum authorisation with cookies

I'm making an app, that saves a sanctum authentication token as a cookie in the browser with HTTPOnly set to true. I understand that once I want to include this cookie in a request I have to make sure that I add to my request credentials: "include". In my request I added the credentials, the body, a header that accepts JSON and the method. Once I make a request to a POST route in my API's which has the sanctum auth:sanctum guard, it returns a 401 error saying the request is unauthorised. The token is valid because when I use the same token in a postman request in the headers as authorization it works just as intended. The whole purpose of this is to make my application safer by using HTTPOnly and eventually Secure as well but since I'm only in development right now, I have that cookie setting set as false.

0 likes
0 replies

Please or to participate in this conversation.