I have two applications: SPA built with Vuejs 3 and the API built with Laravel. the SPA is running on 127.0.0.1:5173 and the api is running on 127.0.0.1:8000 The user can authenticate successfully but I Want logging out it's not working, the user stays authenticated without any error thrown
logout function :
public function logout(Request $request)
{
if(method_exists(auth()->user()->currentAccessToken(), 'delete')) {
$request->user()->currentAccessToken()->delete();
}
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return response()->json([
'success' => true,
]);
}
axios request :
logout() {
return new Promise((resolve, reject) => {
axios
.post('/api/v1/auth/logout')
.then((response) => {
resolve(response)
})
logout route :
//api.php
Route::prefix('/v1')->group(function () {
Route::group(['prefix' => 'auth'], function () {
Route::post('logout', [AuthController::class, 'logout'])->middleware('auth:sanctum');
});
.....