1
votes

I want to use laravel\sanctum with SPA Authentication, where Laravel is backend api and Vue is frontend SPA. I do all manual says about it, but I faced with problem:
when my logout route in api.php

Route::post('/logout', [AuthController::class, 'logout'])

is under middleware('auth:sanctum') I couldn't logout the user because of error:

Method Illuminate\Auth\RequestGuard::logout does not exist.    

where logout function is:

Auth::logout();

But when I remove middleware('auth:sanctum') - logout function works great and user log out.
The question is: Should the logout route be protected or not?

Addition: for those, who want to said: use Auth::logout('web') - it doesn't work, because the user remains logged in.

1

1 Answers

0
votes

You have to explicitly use guard. Change web with your custom guard:

Auth::guard('web')->logout();