Fix for api not being to see session data

so there was an error when trying to use services for API controllers
that was happening because the api middleware didn't pass the same info
as web middleware, resulting in session info not being passed to
controllers used in the api

after a bit of reading discovered necessary middleware could be added to
api routing so session data is available in in api routing

whew
This commit is contained in:
ro 2024-03-07 13:45:45 -06:00
parent 166e19a656
commit 65854e3dbd
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
2 changed files with 5 additions and 5 deletions

View file

@ -42,6 +42,11 @@ class Kernel extends HttpKernel
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class . ':api', \Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
//added middleware so api has access to session data
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
], ],
]; ];

View file

@ -1,6 +1,5 @@
<?php <?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Http\Controllers\API\AuthAPIController; use App\Http\Controllers\API\AuthAPIController;
@ -16,7 +15,3 @@ use App\Http\Controllers\API\AuthAPIController;
*/ */
Route::get("/v1/status", [AuthAPIController::class, 'status']); Route::get("/v1/status", [AuthAPIController::class, 'status']);
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});