aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/items/create/+page.server.ts
blob: 1e6dacb4e8ca705afa1e6f1dfe76537802782459 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fail, redirect } from "@sveltejs/kit";
import { fd, auth, post } from "$lib/utils";

export const actions = {
  default: async ({ cookies, request, url }) => {
    const form = await fd(request);
    try {
      await post("/items", form, auth(cookies));
    } catch (e: any) {
      return fail(400, { message: e.message });
    }

    const success = `/${url.pathname.split("/")[1]}`;
    redirect(307, success);
  },
};