Reputation: 151
How can I call log out on the automatic expiration of session in Laravel? I already added this in session.php
'lifetime' => 10,
'expire_on_close' => true,
Upvotes: 1
Views: 5283
Reputation: 151
Handle it using JS - (working fine in my project)
/*
* this script is for manage the logout of timeout
* if user is inactive for 15 min
* he will be logout :
*
* */
var logout = 'Are you sure to logout?';
var timeout;
var url = ''; // route path;
document.onmousemove = function(){
clearTimeout(timeout);
timeout = setTimeout(function () {
var confirmstatus = confirm( logout );
if(confirmstatus === true) {
var redirect = $.ajax({
cache: false,
url: url,
type: "GET",
headers: {
'X-CSRF-TOKEN': window.project.csrfToken
},
contentType: false,
processData: false,
success: function (response) {
window.location.href = url;
}
});
}
}, 60000*15);
};
</script>
Upvotes: 2
Reputation: 21681
You should try the below solution.
Use Auth;
public function logout(Request $request) {
Auth::logout();
return redirect('/login');
}
Upvotes: 0