Joe Lowery
Joe Lowery

Reputation: 572

Laravel 4.2 - Can't logout

I've set up a basic authentication routine in Laravel 4.2 and I've found that once I've logged in to view a protected page (/spotlight), I can't seem to log out - I always have access to that page. Further weirdness (and maybe clues) if I visit the login page, and then go to the site root to check status, it shows that I have logged out. However, if I then go to /spotlight, the pageis displayed and a subsequent trip to the site root returns 'logged in.'

And yes, I do have the remember_token column (varchar(100), NULL yes, Default = NULL) established.

The relevant routes:

Route::get('/login', function()
{
    return View::make('login');
});

Route::post('/login', function()
{
    $credentials = Input::only('username', 'password');
    if (Auth::attempt($credentials)) {
        return Redirect::intended('/');
    }
    return Redirect::to('login');
});

Route::get('/logout', function()
{
    Auth::logout();
    return View::make('logout');
});

Route::get('spotlight', array(
    'before' => 'auth.basic' ,
    function()
{
    return View::make('spotlight');
}
));

What am I misssing?

Thanks - Joe

Upvotes: 2

Views: 868

Answers (2)

Anthony Vipond
Anthony Vipond

Reputation: 1957

Basic auth doesn't support logout. This is not a limitation to Laravel, HTTP Basic Authorization is not designed to handle logging out. The client will remain logged in until the browser is closed.

Upvotes: 2

Joe Lowery
Joe Lowery

Reputation: 572

Looks like the issue is in using auth.basic rather than just auth as a filter. When I switched to auth and a custom login page, it all worked.

Hope this helps someone else.

Best - Joe

Upvotes: 1

Related Questions