Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ManojKiranA/4f7bf9d65dabba2fcef2d3c510ea50ff to your computer and use it in GitHub Desktop.
Save ManojKiranA/4f7bf9d65dabba2fcef2d3c510ea50ff 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment