Ad

Logout On Automatic Expiration Of Session In Laravel

- 1 answer

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, 
Ad

Answer

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>
Ad
source: stackoverflow.com
Ad