import { auth } from "@pkg/logic/domains/auth/config.base";
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";

export const load = (async (c) => {
	const sess = await auth.api.getSession({
		headers: c.request.headers,
	});
	if ((!sess?.user || !sess?.session) && c.url.pathname !== "/auth/login") {
		return redirect(302, "/auth/login");
	}
	return { user: c.locals.user, session: c.locals.session };
}) satisfies LayoutServerLoad;
