Take a look at Sanctum it should cover your needs https://laravel.com/docs/11.x/sanctum
Protect routes in api routes file
Hello
I try to protect the routes in the API routes file. So that the route can only be accessed if a user is logged in.
Its a laravel, jetstream, inertia, vue3 app, and I make fetch requests which go to the API routes file, to load data to the frontend.
I try the following:
Route::post('/save-word', [ChapterController::class, 'saveWord'])->middleware('auth:sanctum')->name('save-word');
But even if I am loggen in, the request does not pass through.
Now, my question is, is it as easy as simply use auth.sanctum or is there other stuff I have to configure first. I thought that with inertia and jetstream everything should be pre-configured.
Anyone has a thought on this? Thanks in advance
@DanielJohan Jetstream uses Sanctum behind the scenes.
Laravel Jetstream is a beautifully designed application starter kit for Laravel and provides the perfect starting point for your next Laravel application. Jetstream provides the implementation for your application's login, registration, email verification, two-factor authentication, session management, API via Laravel Sanctum, and optional team management features.
Please or to participate in this conversation.