Saturday, 17 August 2013

Auth::logout() is ignored in Laravel 4

Auth::logout() is ignored in Laravel 4

I have one user class which consists of two types of users and want to
allow different users to go to different pages.
I have created a filter as follows
Route::filter('isExpert', function()
{
$userIsExpert = 0;
$userIsLoggedIn = Auth::check();
if ($userIsLoggedIn && Auth::user()->role == 'expert') {
$userIsExpert = 1;
}
Log::info('Logged in: ' . $userIsLoggedIn . ' && Expert: ' .
$userIsExpert);
if ($userIsExpert == 0)
{
Log::info('should be logging out now.');
Auth::logout();
return Auth::basic();
}
});
And routing like so
Route::get('/winners', array('before' => 'isExpert', function()
{
$winners = DB::select('select * from winners');
return View::make('winners.index')->with('winners',$winners);
}));
The thought is this: If it's not an expert, it will logout and redirect to
login page. If it is, it will simply continue. However, Auth::logout();
doesn't ever log out the user.
Question
Why is not Auth::logout() working? I've tried placing it anywhere in the
app to no avail.
cheers

No comments:

Post a Comment