import { deleteSession } from "$lib/database";
import { COOKIE_NAME } from "$lib/constants";

/** @type {import('./$types').RequestHandler} */
export async function GET({ request, cookies, getClientAddress }) {
	const session = cookies.get(COOKIE_NAME);
	if (!session)
		return new Response("", {
			status: 302,
			headers: { location: "/landing" }
		});

	cookies.delete(COOKIE_NAME, { secure: !!process.env.PRODUCTION });
	await deleteSession(session, request.headers.get("x-forwarded-for") || getClientAddress());

	return new Response("", {
		status: 302,
		headers: { location: "/landing" }
	});
}
