Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Auth logout not working

Tags:

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?

like image 927
mikelovelyuk Avatar asked Feb 26 '15 16:02

mikelovelyuk


People also ask

How do I remove auth session in laravel?

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

What is Auth logout in Laravel?

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.

How to use signincontroller with logoutuser using route?

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.

Is it possible to add an exception to logout a route?

this ocurrs because the middleware is called for every route. you can add a exception to " logout route" in App\Http\Middleware\RedirectIfAuthenticated.php

Why can't I get the authcontroller to logout?

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']);


2 Answers

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)

like image 157
lorey Avatar answered Oct 06 '22 20:10

lorey


Try this..

Put In following code "class AuthController extends Controller"

public function getLogout()     {         $this->auth->logout();         Session::flush();         return redirect('/');     } 
like image 42
Deenadhayalan Manoharan Avatar answered Oct 06 '22 20:10

Deenadhayalan Manoharan