Last active
June 23, 2020 08:45
-
-
Save tanthammar/88c7a28b68573f70dc3d09abb26d454b to your computer and use it in GitHub Desktop.
Keep livewire form session alive (419)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script data-turbolinks-eval=false> | |
function updateToken() { | |
fetch('/update-csrf') | |
.then(response => response.text()) | |
.then(csrf => { | |
document.head.querySelector('meta[name="csrf-token"]').setAttribute('content', csrf) | |
}) | |
} | |
setInterval(updateToken, 1000 * 60 * 5) | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('update-csrf', fn () => response(csrf_token()))->middleware('auth'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an improved version, without csrf route
https://gist.github.com/tanthammar/02c615e73022c44dda6533ed9416ac29