aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/settings.ts
blob: fa1abc03dd7f92ffca2f34c8413609be58c0c948 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { auth, fd, 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 === "account") {
    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";
    form.bip353 = form.bip353 === "on";
  }

  try {
    const { user } = await post("/user", form, auth(cookies));

    if (user.language) cookies.set("lang", user.language, { path: "/" });

    return { user, success: true };
  } catch (e) {
    const { message } = e as Error;
    return fail(400, { message });
  }
};