I have an application that has the following setup:
Laravel
Host: appname.local:8000
Environment variables:
Angular
Host: appname.local:4200
What works at the moment:
Angular methods to get token and authenticate user
Session database entry after successful authentication
What does not work:
Subsequent requests to routes that are protected by the following middleware: auth:sanctum all result in unauthenticated responses. The HTTP requests never make it to my controllers.
But I can see in the developer's console that the cookies are being sent. So I don't understand why Sanctum isn't picking up the auth
I've followed several tutorials and I can't seem to understand why Laravel's Authenticate middleware is unable to see that I've already authenticated my user.
Does anyone know what I could be doing wrong?
The answers provided by @agm1984 and @Eden Webstudio were quite useful. However, they did not solve my issue.
After additional debugging, I noticed that sanctum's guard logic looks for a guard in
config/sanctum.php
. Its default value is web. My default guard for the protected routes is the api guard which is the guard that I used during the authentication process.
After setting the guard key in config/sanctum.php with 'api' the authentication seems to be working smoothly. To be honest, I can't remember why I decided to the session driver for my api guard.
config/auth.php