I have in my Laravel 8 application and as Auth System I use Laravel Breeze. I have defined several web routes and api routes. Some of them protect via Auth .
web route: (get|post::middleware(['auth'])->..)
api route: (get|post::middleware(['auth:api'])->..)
in the kernel.php i have added in the middlewareGroups -> api array:
'api' => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateSessionMiddlewareStartSession::class,
'throttle:api',
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
In the config/auth.php I have set the api driver to session under Guards. By default it is set to token here.
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'session',
'provider' => 'users',
'hash' => false,
],
],
Unfortunately, it does not work with the api routes. I keep getting {"message": "Unauthenticated."}. Even if the user is logged in.
Can someone tell me what is not working here?
question from:
https://stackoverflow.com/questions/65901640/laravel-8-cant-use-api-and-web-route-at-the-same-time 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…