aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/items/create/+page.server.ts
blob: 2e006a3ee71cf427e5fce58b44064b4f71c71956 (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 }) => {
    let form = await fd(request);
    try {
      await post("/items", form, auth(cookies));
    } catch (e: any) {
      return fail(400, { message: e.message });
    }

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