You should ensure that you send the Accept: application/json header with your request.
Dec 3, 2021
3
Level 4
Laravel Sanctum middleware
Hi, I am building a Vue-based SPA application. Therefore, in my web routes, I have the Auth routes (login and register) publically available, and the below default route basically serves my SPA. But when I add the auth:sanctum I am redirected back to the '/login' page however my token is generated successfully as well as XSRF-TOKEN and laravel_session cookie.
Route::middleware('auth:sanctum')->group(function () {
// fallback route (all routs that don't have api in it will be handled by Vue)
Route::get('/{any?}', function () {
return view('welcome');
})->where('any', '^(?!api\/)[\/\w\.\,-]*');
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
});
As far as I understand the auth:sanctum should check if the session, cookie and token is set which apparetly gets set as I try to log in.
Any chance you could please help me understand why is that?
Please or to participate in this conversation.