Created
October 11, 2016 04:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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