fix: login sessions

This commit is contained in:
Andy Burke 2025-07-04 14:51:49 -07:00
parent dc91d0ab8c
commit cf46450f5f
11 changed files with 179 additions and 27 deletions

View file

@ -1,6 +1,6 @@
document.addEventListener("DOMContentLoaded", () => {
/* make all forms semi-smart */
const forms = document.querySelectorAll("form");
const forms = document.querySelectorAll("form[data-smart]");
for (const form of forms) {
const script = form.querySelector("script");
@ -21,17 +21,27 @@ document.addEventListener("DOMContentLoaded", () => {
}
const url = form.action;
const method = form.dataset.method ?? "POST";
console.dir({
method,
form,
});
try {
// TODO: send session header
const response = await fetch(url, {
method: "POST",
const options = {
method,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
};
if (["POST", "PUT", "PATCH"].includes(method)) {
options.headers["Content-Type"] = "application/json";
options.body = JSON.stringify(body);
}
const response = await fetch(url, options);
if (!response.ok) {
const error_body = await response.json();