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 { SignupError, roleFromLevel, validateSignupToken } from "@emdash-cms/auth";

//#region src/astro/routes/api/auth/signup/verify.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 result = await validateSignupToken(createKyselyAdapter(emdash.db), token);
		return apiSuccess({
			success: true,
			email: result.email,
			role: result.role,
			roleName: roleFromLevel(result.role)
		});
	} catch (error) {
		if (error instanceof SignupError) return apiError(error.code.toUpperCase(), error.message, {
			invalid_token: 404,
			token_expired: 410,
			user_exists: 409,
			domain_not_allowed: 403
		}[error.code] ?? 400);
		return handleError(error, "Failed to validate signup token", "SIGNUP_VERIFY_ERROR");
	}
};

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