import { N as redirect } from '../chunks/utils.js-mIi_c4Oz.js';
import { g as getSessionUser, h as hasAnyAdmin } from '../chunks/auth.js-D502gejJ.js';
import '../chunks/utils2.js-BQzn9ikS.js';
import 'node:crypto';
import '../chunks/db.js-le-jjQPv.js';
import 'node:sqlite';
import 'node:fs';
import 'node:path';
import 'node:os';

const PUBLIC_PREFIXES = ["/login", "/setup"];
const handle = async ({ event, resolve }) => {
  event.locals.user = getSessionUser(event.cookies);
  const { pathname } = event.url;
  const isPublic = PUBLIC_PREFIXES.some((p) => pathname === p || pathname.startsWith(p + "/"));
  if (!hasAnyAdmin() && pathname !== "/setup") {
    throw redirect(303, "/setup");
  }
  if (hasAnyAdmin() && pathname === "/setup") {
    throw redirect(303, event.locals.user ? "/" : "/login");
  }
  if (!event.locals.user && !isPublic) {
    const next = encodeURIComponent(pathname + event.url.search);
    throw redirect(303, `/login?next=${next}`);
  }
  return resolve(event);
};

export { handle };
//# sourceMappingURL=hooks.server.js-Dgw5uz_D.js.map
