Skip to content

Instantly share code, notes, and snippets.

@Jeff-P
Created October 11, 2016 04:19
Show Gist options
  • Save Jeff-P/09cc52b0dbbb6d4ceb08aa160de7a867 to your computer and use it in GitHub Desktop.
Save Jeff-P/09cc52b0dbbb6d4ceb08aa160de7a867 to your computer and use it in GitHub Desktop.
Laravel 5.3 Auto-check if user is logged in if not refresh page to save page after login
//create new route
Route::get('/checkAuth', function() {
})->middleware('auth');
//add this script to your master layout file
<script>
setInterval(function() {
$.ajax({
'url': '/checkAuth',
'success': function (response) {
if (response == true) {
}
},
error: function( jqXhr, textStatus, errorThrown ){
if (errorThrown == 'Unauthorized') {
location.reload();
}
}
});
}, 1000 * 60 * 1); // will check every minute for Auth
</script>
// that is all, every page will have the script embeded and will run every minute to check if logged in. If not the page will refresh forcing a login then return you back to the page you were at
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment