php - Laravel 5 - Checking if the user session has expired -


i trying implement way check if user session has expired , pop-up modal letting user know.

here have far.

route

route::get('auth-check', ['uses' => 'userscontroller@authcheck', 'as' => 'auth.check']); 

userscontroller

use illuminate\contracts\auth\guard;  class userscontroller extends controller {      public function __construct(guard $auth)     {         $this->auth = $auth;     }  ...      /*     * returns {status: false} or {status: true}     */     public function authcheck()     {         return response(['status' => $this->auth->check()])                       ->header('content-type', 'application/json');     }  } 

master blade (so can checked on page)

<!-- modal --> <div class="modal fade" id="session-expired">     <div class="modal-dialog">         <div class="modal-content">             <div class="modal-header">                 <h4 class="modal-title">session expired!</h4>             </div>             <div class="modal-body">                 <p>your session has expired, please login continue.</p>             </div>             <div class="modal-footer">                 <a href="{!! route('login') !!}" class="btn btn-danger">login</a>             </div>         </div>     </div> </div> 

js

@if(auth::check()) $.fn.timer = function() {     $.get("{{ route('auth.check') }}", function (data) {         data.status == false ? $('#session-expired').modal({ show: true, backdrop: 'static' }) : $('#session-expired').modal('hide');     }); };  window.setinterval(function(){     $('#timedoutsession').timer(); },10000); @endif 

it kinda works, when logged in returns {status: true}. after 5-10 requests on checking auth user session dies reason , returns {status: false}. making many auth checks kills session security measure or something.

anyone mess around letting user know if session has expired? reason being application form based , users may leave form page open , come in next day , session has expired go through process of filling out lengthy form , submit find out not logged in.

any ideas or better ways quite welcome.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -