import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import { a as unwrapResult, r as handleError, t as apiError } from "../../../../../error-CkAseSqZ.mjs";
import { n as parseBody, t as isParseError } from "../../../../../parse-GmjecGct.mjs";
import "../../../../../api-tokens-DsvvCtdh.mjs";
import "../../../../../oauth-user-lookup-Bsc_GsX-.mjs";
import { t as handleDeviceAuthorize } from "../../../../../device-flow-CfGP18Uw.mjs";
import { z } from "zod";

//#region src/astro/routes/api/oauth/device/authorize.ts
const prerender = false;
const authorizeSchema = z.object({
	user_code: z.string().min(1),
	action: z.enum(["approve", "deny"]).optional()
});
const POST = async ({ request, locals }) => {
	const { emdash } = locals;
	const { user } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	if (!user) return apiError("NOT_AUTHENTICATED", "Authentication required", 401);
	try {
		const body = await parseBody(request, authorizeSchema);
		if (isParseError(body)) return body;
		return unwrapResult(await handleDeviceAuthorize(emdash.db, user.id, user.role, body));
	} catch (error) {
		return handleError(error, "Failed to authorize device", "AUTHORIZE_ERROR");
	}
};

//#endregion
export { POST, prerender };
//# sourceMappingURL=authorize.mjs.map