0

When I log out with auth:sanctum middleware , the user_id field on sessions tabel is not set to null, unlike when I don't use it.

Route::post('/logout', function (Request $request) {
    Auth::guard('web')->logout();
    $request->session()->invalidate();
    $request->session()->regenerateToken();
    return ['done' => 'ok'];
})->middleware('auth:sanctum');

user id same : enter image description here

The problem is that I have routers that use this middleware and sometimes I need to log out for some reason. When using auth:sanctum, the user_id is not set to null.

i don't use tokens , i use sessions and cookies with sanctum, and sessions driver is database

1 Answer 1

0

The solution that worked for me, but I don't know if it is right or wrong, is instead of using auth:sanctum, use auth only as middleware.

Route::post('/logout', function (Request $request) {
    Auth::guard('web')->logout();
    $request->session()->invalidate();
    $request->session()->regenerateToken();
    return ['done' => 'ok'];
})->middleware('auth');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.