1

I want to redirect user automatically to the login page when session expires.

I know by Auth::check() i can check if user session exist or not. but if user refresh the page then only it is redirecting to login.

Suppose user's session expires, then immediately i want to redirect to login page without waiting for user to refresh the page.

Is it possible. please tell me the right way to do it.

Vikash
  • 3,391
  • 2
  • 23
  • 39
  • 1
    This may help you. [Automatic Redirect On LogIn Page](http://stackoverflow.com/questions/19334370/automatically-redirect-to-login-page-after-session-timeout-jsp-spring) – jay bhut Feb 02 '17 at 07:24
  • Is there any way i can read the response code of a ajax request at one single place. I have a very big application and almost 500+ajax request is there. whenever i am making the ajax request and if session has expired then it is throwing error and it is obvious that request is not getting any response. what maximum i can do i can provide one message by 401 status code, i can check that code where i am making the ajax request and redirect, but i can't do the same for 500+ request. i want to redirect after that to login page by writing a code which will check all ajax request and redirect. – Vikash Feb 02 '17 at 07:53

1 Answers1

0

I thing is not possible to with out any click you need a click listener as work with ajax like this

in env file so find line SESSION_LIFETIME=10 value change as wish in minate

and now

 $.ajax({
        type: "GET",
        url: filename,
        contentType: false,
        success: function (data) {
           // loaded your content without expire the sessions
        },
        error: function (xhr, status, error) {

           // you redirect tht to login page 
           //hint: the laravel has unauthorized error for session expire or for Unauthorized users
            if (error === 'Unauthorized'){
                location.assign("login");
            }
        }
    });
Rahman Rezaee
  • 1,943
  • 16
  • 24