Skip to content

Instantly share code, notes, and snippets.

@tanthammar
Last active June 23, 2020 08:45
Show Gist options
  • Save tanthammar/88c7a28b68573f70dc3d09abb26d454b to your computer and use it in GitHub Desktop.
Save tanthammar/88c7a28b68573f70dc3d09abb26d454b to your computer and use it in GitHub Desktop.
Keep livewire form session alive (419)
<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>
Route::get('update-csrf', fn () => response(csrf_token()))->middleware('auth');
@tanthammar
Copy link
Author

Here is an improved version, without csrf route
https://gist.github.com/tanthammar/02c615e73022c44dda6533ed9416ac29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment