Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force logout using user id in Laravel?

Tags:

laravel

I'm wondering if there is any simple way to force logout different users by their id? For example I need to block currently lodged in user so I want to log out him after I set his status to block.

P.S. I cant use middleware for this to check on each request.

like image 596
Kin Avatar asked Dec 05 '22 17:12

Kin


1 Answers

I do this inside the Authenticate middleware

if (!Auth::user()->isActive()) {
    Auth::logout();

    return Redirect::home();
}

The user is already loaded there, no additional database query is needed here.

I don't think that's a performance issue, you just do a little if statement and you do it only if the user needs to be authenticated.

like image 134
Elie Faës Avatar answered May 18 '23 00:05

Elie Faës