when implementing authentication in laravel using sentry and logging out, then if I press 'go back one page' button of any browser it goes back to the dashboard. If the page is refreshed, it goes to the login page as desired. But I want to prevent accessing dashboard without refreshing.
N.B. After logging out and going to the dashboard in this manner prevents from changing anything as needed.
Destroy the Session when you call the logout function. Simply write your logout function in your controller like this:
public function getLogout() {
Sentry::logout();
Session::flush(); // Insert this line, it will remove all the session data
return Redirect::to('users/login')->with('message', 'Your are now logged out!');
}
Edit:
First I used only Session:flush(), and somehow it worked! But when I checked again, I found that it's not working. So, we need to add some code more to clear the browser cache when log out.
Using filter can be a solution for this problem. (I didn't find any other solution yet) First, add this code in filters.php :
Route::filter('no-cache',function($route, $request, $response){
$response->header("Cache-Control","no-cache,no-store, must-revalidate");
$response->header("Pragma", "no-cache"); //HTTP 1.0
$response->header("Expires"," Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
});
Then attach this filter to routes or controllers. I attached it into construct function of controller like this:
public function __construct() {
$this->beforeFilter('csrf',array('on' => 'post'));
$this->afterFilter("no-cache", ["only"=>"getDashboard"]);
}
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