php - Handling expired token in Laravel -


what best way handle expired tokens in laravel 5.

i mean have page , has links perform ajax requests. work fine when page loaded when wait sometime token mismatch error.

now, have refresh page make work again. but, don't want refresh page. want way refresh token or other work around make fix.

i hope got point.

a work around it, new token every time, otherwise defeating purpose of csrf token:

<html>     <head>         <meta name="csrf_token" content="{{ csrf_token() }}">     </head>     <body>         <script type="text/javascript">             var csrftoken = $('[name="csrf_token"]').attr('content');              setinterval(refreshtoken, 3600000); // 1 hour               function refreshtoken(){                 $.get('refresh-csrf').done(function(data){                     csrftoken = data; // new token                 });             }              setinterval(refreshtoken, 3600000); // 1 hour           </script>     </body> </html> 

in laravel routes

route::get('refresh-csrf', function(){     return csrf_token(); }); 

i apologize in case of syntax errors, haven't used jquery long time, guess idea


Comments