I've developed multiple traditional Laravel 5.x web apps with blade & Vue components, but now I'm developing a new Laravel 7 SPA app with React and Sanctum and I have installed the UI/Auth package (which is now separate).
I can log in with my React/Axios form, but can't get the logged in user (with "Auth::user()") in routes defined in "routes/api.php". But when I define a different route in "routes/web.php" that calls the exact same controller/method, I DO get the logged in user.
Maybe it has something to do with middleware definitions in "app/Http/Kernel.php" - I have:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
Any thoughts?