for what routes?
laravel sanctum and default `auth:web`
Just because my understanding of the sanctum package seems to be wrong in some places:
1.) I thought by reading the config of sanctum it will use the default
/*
|--------------------------------------------------------------------------
| Sanctum Guards
|--------------------------------------------------------------------------
|
| This array contains the authentication guards that will be checked when
| Sanctum is trying to authenticate a request. If none of these guards
| are able to authenticate the request, Sanctum will use the bearer
| token that's present on an incoming request for authentication.
|
*/
'guard' => ['web'],
web guard, meaning users which are already logged in on the website (using default laravel authentication) would be able to view routes, protected by auth:sanctum?
In my tests the users remain unauthenticated and won't get access to the routes, even if they are autenticated by laravel, is there some kind of missunderstanding?
2.) How to achieve it to be able to access a route, either by passing a bearerToken or just by being authenticated by laravel (using default session cookie)?
Either using Route::middleware(['auth:sanctum', 'auth:web']) wasn't able to do the trick.
3.) What is the EnsureFrontendRequestsAreStateful middleware being used for?
'api' => [
//\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
It was commented out so I leave it as it is.
@Snapey here the full breakdown:
https://stackoverflow.com/a/78884786/16222896
it turns out sanctums guard is just for the own implementation of cookies when using sanctum,
To protect a route by either bearer token (sanctum) or the default laravel authentication (auth:web) you would need to create a custom middleware for.
Thanks for your help, you're a helpful member of laracasts!
Please or to participate in this conversation.