laravelauthenticationsingle-page-applicationlaravel-8laravel-sanctum

Laravel 8 Sanctum SPA Auth - Session store not set on request


I'm trying to implement Sanctum SPA Authentication. I'm getting the following error when trying to login (only in production):

production.ERROR: Session store not set on request. {"userId":1,"exception":"[object] (RuntimeException(code: 0): Session store not set on request. at /app/vendor/laravel/framework/src/Illuminate/Http/Request.php:483)

Followed all the steps in the documentation. First calling sanctum/csrf-cookie GET request, then my API login POST request with the session cookie attached. Thank you for any tips!

My login method in AuthController.php, where the exceptioin is happening on line 28.

enter image description here

My Http\Kernel.php file with the middleweres for the API endpoints.

enter image description here

My API endpoint in routes/api.php

enter image description here


Solution

  • The authentication routes must be in the routes/web.php file.