I have login route in my web routes php but I get this error while redirecting to login route.. It's not api, I think to use Sanctum SPA authantication.. How to configure it properly?
this is my login route and protected routes.. Authanticate middleware gives that error.
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : route('login');
}
}
@hupp yes I can see the route in route list. by the way, with auth:sanctum or just auth protection it's same.
@im-nazmul I run php artisan optimize after every change.
If you're using Inertia make sure your login route is in web.php not api.php
When you don't plan to use separate spa with e.g. Vue CLI that needs to connect to your Laravel app you don't need api routes.
Inertia already connects your front end for e.g. Vue with the backend without the need of api routes/calls.
INERTIA Build single-page apps, without building an API. Create modern single-page React, Vue, and Svelte apps using classic server-side routing. Works with any backend — tuned for Laravel.
@gych I use web routes. already wrote in my question. I sat session driver from file to cookie in .env file.. I don't know what are other configurations.. according to doc it must work only with web routes.
These kits automatically scaffold your application with the routes, controllers, and views you need to register and authenticate your application's users.