Skip to content

Instantly share code, notes, and snippets.

@er2
Last active March 31, 2023 14:02
Show Gist options
  • Save er2/f8a999231a550a555b9977ac2c36d582 to your computer and use it in GitHub Desktop.
Save er2/f8a999231a550a555b9977ac2c36d582 to your computer and use it in GitHub Desktop.
HTMX plus Supabase
<script src="https://unpkg.com/htmx.org@1.8.4"></script>
<script>
document.body.addEventListener('htmx:configRequest', function(evt) {
const key = '<your key here>';
evt.detail.headers['apikey'] = key;
evt.detail.headers['Authorization'] = "Bearer " + key;
});
document.body.addEventListener('htmx:beforeSwap', function (evt) {
// trim quotes from response
evt.detail.serverResponse = evt.detail.serverResponse.slice(1, -1);
});
</script>
<h2>This is an experiment with hooking up HTMX straight to Supabase</h2>
<div hx-post="https://<your id here>.supabase.co/rest/v1/rpc/home"
hx-trigger="load">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment