aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-08 15:19:04 -0800
committerAdam Soltys <[email protected]>2024-11-08 15:19:04 -0800
commit84fb4b209a2650b2a93f3208ee9a23a44d8283c7 (patch)
tree8687566bd8eac12de99439d448773d8ce5dc34b4 /src/lib
parent32fcc461cd43c8907df5e306d520bb671307eab1 (diff)
downloadcoinos-ui-84fb4b209a2650b2a93f3208ee9a23a44d8283c7.tar.gz
coinos-ui-84fb4b209a2650b2a93f3208ee9a23a44d8283c7.zip
svelte 5 fixups
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/settings.ts31
-rw-r--r--src/lib/store.ts1
2 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/settings.ts b/src/lib/settings.ts
new file mode 100644
index 00000000..b78d83fe
--- /dev/null
+++ b/src/lib/settings.ts
@@ -0,0 +1,31 @@
+import { auth, fd, get, post } from "$lib/utils";
+import { fail } from "@sveltejs/kit";
+
+type Error = {
+ message: string;
+};
+
+export default async ({ cookies, request }) => {
+ const form = await fd(request);
+
+ if (form.tab === "pos") {
+ form.notify = form.notify === "on";
+ form.push = form.push === "on";
+ form.nip5 = form.nip5 === "on";
+ form.prompt = form.prompt === "on";
+ form.autowithdraw = form.autowithdraw === "on";
+ }
+
+ let user = { ...(await get("/me", auth(cookies))), ...form };
+
+ try {
+ ({ user } = await post("/user", user, auth(cookies)));
+ } catch (e) {
+ const { message } = e as Error;
+ return fail(400, { message });
+ }
+
+ if (user.language) cookies.set("lang", user.language, { path: "/" });
+
+ return { user, success: true };
+};
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 5c7a0957..e294329e 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -61,3 +61,4 @@ export const theme = writable("light");
export const token = persistSession("token");
export const ndef = writable();
export const showQr = persistLocal("showQr", true);
+export const save = writable();