Support CSRF in HTMX non-form posts.

This commit is contained in:
mikestefanello 2021-12-23 19:29:12 -05:00
parent b2f64b62f4
commit 8860b981e6
3 changed files with 14 additions and 0 deletions

View File

@ -19,4 +19,14 @@
{{define "js"}}
<script src="https://unpkg.com/htmx.org@1.6.1"></script>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
{{end}}
{{define "footer"}}
{{- if .CSRF}}
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.parameters['csrf'] = '{{ .CSRF }}';
})
</script>
{{end}}
{{end}}

View File

@ -23,5 +23,7 @@
</div>
</div>
</section>
{{template "footer"}}
</body>
</html>

View File

@ -38,5 +38,7 @@
</div>
</div>
</section>
{{template "footer"}}
</body>
</html>