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

export async function load({ cookies, url }) {
	let connected;

	const query = url.searchParams.toString();

	try {
		await get(`/square/auth?${query}`, auth(cookies));
		connected = true;
	} catch (e) {
		const { message } = e as Error;
		fail(400, { message });
	}

	if (connected) redirect(307, "/settings/account");
}