import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CkAseSqZ.mjs";
import { createKyselyAdapter } from "@emdash-cms/auth/adapters/kysely";
import { InviteError, roleFromLevel, validateInvite } from "@emdash-cms/auth";

//#region src/astro/routes/api/auth/invite/accept.ts
const prerender = false;
const GET = async ({ url, locals }) => {
	const { emdash } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	const token = url.searchParams.get("token");
	if (!token) return apiError("MISSING_PARAM", "Token is required", 400);
	try {
		const invite = await validateInvite(createKyselyAdapter(emdash.db), token);
		return apiSuccess({
			success: true,
			email: invite.email,
			role: invite.role,
			roleName: roleFromLevel(invite.role)
		});
	} catch (error) {
		if (error instanceof InviteError) return apiError(error.code.toUpperCase(), error.message, {
			invalid_token: 404,
			token_expired: 410,
			user_exists: 409
		}[error.code] ?? 400);
		return handleError(error, "Failed to validate invite", "INVITE_VALIDATE_ERROR");
	}
};

//#endregion
export { GET, prerender };
//# sourceMappingURL=accept.mjs.map