diff options
| author | Adam Soltys <[email protected]> | 2024-11-08 15:19:04 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-08 15:19:04 -0800 |
| commit | 84fb4b209a2650b2a93f3208ee9a23a44d8283c7 (patch) | |
| tree | 8687566bd8eac12de99439d448773d8ce5dc34b4 /src/lib/settings.ts | |
| parent | 32fcc461cd43c8907df5e306d520bb671307eab1 (diff) | |
| download | coinos-ui-84fb4b209a2650b2a93f3208ee9a23a44d8283c7.tar.gz coinos-ui-84fb4b209a2650b2a93f3208ee9a23a44d8283c7.zip | |
svelte 5 fixups
Diffstat (limited to 'src/lib/settings.ts')
| -rw-r--r-- | src/lib/settings.ts | 31 |
1 files changed, 31 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 }; +}; |
