2025-03-23 16:37:43 -04:00
|
|
|
(() => {
|
|
|
|
const self = reg_ns("me");
|
|
|
|
|
|
|
|
self.define("logout", async () => {
|
|
|
|
if (
|
|
|
|
!(await trigger("atto::confirm", [
|
|
|
|
"Are you sure you would like to do this?",
|
|
|
|
]))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch("/api/v1/auth/logout", {
|
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
|
|
|
trigger("atto::toast", [
|
2025-03-24 22:42:33 -04:00
|
|
|
res.ok ? "success" : "error",
|
2025-03-23 16:37:43 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location.href = "/";
|
|
|
|
}, 150);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2025-03-29 00:26:56 -04:00
|
|
|
|
|
|
|
self.define("remove_post", async (_, id) => {
|
|
|
|
if (
|
|
|
|
!(await trigger("atto::confirm", [
|
|
|
|
"Are you sure you want to do this?",
|
|
|
|
]))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/posts/${id}`, {
|
|
|
|
method: "DELETE",
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
|
|
|
trigger("atto::toast", [
|
|
|
|
res.ok ? "success" : "error",
|
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2025-03-23 16:37:43 -04:00
|
|
|
})();
|