Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel sanctum SPA authentication logout is not working

I am using laravel sanctum SPA authentication in my Vue project.Everything is working well but even after logout

Auth::logout()

I am still able to get datas from api route inside middleware

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

I should not be able to get datas after logout.It should show 401 unauthenticated but its not the case. How to solve this problem.I have been stuck here for 3 days.I followed laravel documentation and other tutorial as well but every one logged out same like I did.

like image 226
Pemba Tamang Avatar asked Jan 25 '23 20:01

Pemba Tamang


1 Answers

Kindly use Auth::guard('web')->logout(); instead of Auth::logout(). look into SPA Log out issue

like image 90
ashish.negi Avatar answered Mar 07 '23 14:03

ashish.negi