globalThis.process ??= {};
globalThis.process.env ??= {};
import { r as __exportAll } from "./rolldown-runtime_-UtK6b3T.mjs";
import { d as mapContentError, l as jsonError, u as jsonOk } from "./crypto_CY2zBtG3.mjs";
import { r as buildAuthEngine } from "./admin-engine_Cqzo5vQB.mjs";
import { n as loginWithCredentials, r as logout } from "./auth_B0DWM0G6.mjs";
import { env } from "cloudflare:workers";
//#region src/pages/api/admin/session.ts
var session_exports = /* @__PURE__ */ __exportAll({
	DELETE: () => DELETE,
	POST: () => POST,
	prerender: () => false
});
var POST = async ({ request, cookies }) => {
	if (!request.headers.get("content-type")?.startsWith("application/json")) return jsonError(415, "unsupported_media_type", "content-type must be application/json");
	try {
		const data = await request.json();
		if (typeof data !== "object" || data === null) return jsonError(400, "validation_error", "must be an object");
		const { email, password } = data;
		if (typeof email !== "string" || typeof password !== "string") return jsonError(400, "validation_error", "email and password are required");
		if (email.length > 320) return jsonError(400, "validation_error", "email too long");
		if (password.length > 1024) return jsonError(400, "validation_error", "password too long");
		const principal = await loginWithCredentials(buildAuthEngine(env), cookies, {
			email,
			password
		});
		return jsonOk(principal);
	} catch (error) {
		return mapContentError(error);
	}
};
var DELETE = async ({ request, cookies }) => {
	try {
		await logout(buildAuthEngine(env), cookies, request, env.SITE_ORIGIN);
		return jsonOk({ ok: true });
	} catch (error) {
		return mapContentError(error);
	}
};
//#endregion
//#region \0virtual:astro:page:src/pages/api/admin/session@_@ts
var page = () => session_exports;
//#endregion
export { page };
