0

I'm using auth Sanctum and I can't log out of my account. I don't understand why.

 //controller
public function logout(Request $request){
    Auth::logout();
    $request->session()->invalidate();
    $request->session()->regenerateToken();
    session() -> pull('user');
    return view('admin.login.index');
}

//view
<form method="post" action=" {{ route('logout') }} ">
    @csrf
    <button type="submit"> logout </button>
</form>

1 Answers1

1

Laravel Sanctum is authentication system with token based auth. If you see the Sanctum Doc, there's no Logout option, but there's revoke. I don't know how you use your token (API Token, SPA and Mobile), but you can revoke it with

// Revoke all tokens...
$user->tokens()->delete();

// Revoke the token that was used to authenticate the current request...
$request->user()->currentAccessToken()->delete();

// Revoke a specific token...
$user->tokens()->where('id', $tokenId)->delete();
TheArKa
  • 350
  • 2
  • 5
  • 12