1
votes

I'm just creating a basic application in Laravel 4 and i have one small problem.

My logout function is not working properly... well it works, but:

When a user is signed in and clicks the logout button the user i getting logged out but when i click on the browsers Back-button im getting back to the logged in page.

I'm using the Auth::logout(). Does this method kill the session or does it have todo anything with the browsers cache?

How can i fix this?

My logout function:

public function getLogout(){

    if(Auth::check()){

        Auth::logout();
        return Redirect::route('home');

    }
}

My routes:

/*
 * Authenticated users
 */

Route::group(array('before' => 'auth'), function() {

    Route::get('success', array(

        'as' => 'success',
        'uses' => 'AccountController@getSuccess'

    ));


    Route::get('signout', array(
        'as' => 'signout',
        'uses' => 'AccountController@getLogout'
    ));

  });
4

4 Answers

1
votes

This is browser cache problem.

Try ...

App::after(function($request, $response)
{    
  $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
  $response->headers->set('Pragma','no-cache');
  $response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});
0
votes

You can redirect the user away from the login page if he's already authenticated by simply putting an if-else statement to check that!

0
votes

This is normal behaviour. The browser "remembers" loaded pages and doesn't reload them entirely when you hit the back button, so you'll still see the authentication-only pages even though you've been logged out properly. But any requests made to your app's restricted pages should now fail, because even though the browser is showing you code it rendered back when you were logged-in, it's no longer able to authenticate without your intervention. This is easy to verify:

  1. Log in
  2. Log out
  3. Hit the back button
  4. Refresh the page

You should now be prompted to log in rather than seeing the previous page.

0
votes

@Spoofy, this is an issue with browser caching, read through this link to fix this