Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Auth Logout not destroying session

Tags:

I am using Laravel5 Auth system for my new project, I am able to use registration and login functions with out any problem but logout is not working as expected, however I get redirected to url specified at $redirectAfterLogout but it does not destroy session so even after hitting logout button I am able to see dashboard.

Does laravel has some bug in Auth system, please suggest, thanks

like image 303
seoppc Avatar asked Apr 14 '15 07:04

seoppc


2 Answers

You have not provided any piece of code that you have used. However, the following code works:

public function getLogout(){
    Auth::logout();
    Session::flush();
    return Redirect::to('/');
}

The Session::flush();clears all the existing sessions.

like image 69
Amita Avatar answered Sep 16 '22 15:09

Amita


Using Laravel 5.2, I registered a listener, handled the logout event and called Session::flush as suggested above. Seemed to work pretty well. Hope this is helpful.

EventServiceProvider.php

protected $listen = [
    'App\Events\SomeEvent' => [
        'App\Listeners\EventListener',
    ],
    'Illuminate\Auth\Events\Logout' => [
        'App\Listeners\ClearSessionAfterUserLogout'
    ],
]; 

ClearSessionAfterUserLogout.php

public function handle(Logout $event)
{
    Session::flush();
}
like image 45
ken-mills Avatar answered Sep 19 '22 15:09

ken-mills