When I use the built-in Authentication and try to log the user out at /auth/logout
- it does not work as hoped. It appears to keep the user logged in. But when I clear my browser cache, I can see that is has actually logged the user out.
I don't get any errors on the page nor errors in the log file.
I am guessing that Session::flush()
at the logout method would possibly solve this - but I don't know where to put it.. Can someone point me in the right direction?
The Session::flush(); clears all the existing sessions.
In my previous post, we implement the authentication, now we will talk about Laravel auth logout. Logout is one of the important functionality to implement in a web application when users log in they should have an option to log out of their account and secure it. To shorten this post please follow my previous post here.
Step 1. Create route We are required only one route to call controller. Route::get ('logout', [ 'as' => 'logout', 'uses' => 'SigninController@Logoutuser' ]); Step 2. SigninController with Logoutuser function We will first need to import the Auth namespace. In this step authentication destroy.
this ocurrs because the middleware is called for every route. you can add a exception to " logout route" in App\Http\Middleware\RedirectIfAuthenticated.php
The problem is from the 'guest' middleware in the AuthController constructor. It should be changed from $this->middleware ('guest', ['except' => 'logout']); to $this->middleware ('guest', ['except' => 'getLogout']);
For anyone that has problems solving it with the accepted solution: I started with Laravel 5.1 and updated to 5.2. The following fix worked for me:
Try changing your 'logout' route to
Route::get('auth/logout', 'Auth\AuthController@logout');
or in AuthController constructor add
public function __construct() { $this->middleware('guest', ['except' => ['logout', 'getLogout']]); }
Taken from: https://stackoverflow.com/a/34667356/1275778 (also check the other answers there if you're still having problems afterwards)
Try this..
Put In following code "class AuthController extends Controller"
public function getLogout() { $this->auth->logout(); Session::flush(); return redirect('/'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With