import "../../../../base64-CmWvODNW.mjs";
import "../../../../types-CuW0zWDA.mjs";
import { t as UserRepository } from "../../../../user-BjAOvU3Z.mjs";
import { n as apiSuccess, r as handleError, t as apiError } from "../../../../error-CkAseSqZ.mjs";
import { n as parseBody, t as isParseError } from "../../../../parse-GmjecGct.mjs";
import "../../../../redirects-DXEXBAII.mjs";
import { v as authMeActionBody } from "../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../status-CqJQX1QN.mjs";
import "../../../../api/schemas/index.mjs";

//#region src/astro/routes/api/auth/me.ts
const prerender = false;
const GET = async ({ locals }) => {
	const { user } = locals;
	if (!user) return apiError("NOT_AUTHENTICATED", "Not authenticated", 401);
	const isFirstLogin = !user.data?.welcomeDismissed;
	return apiSuccess({
		id: user.id,
		email: user.email,
		name: user.name,
		role: user.role,
		avatarUrl: user.avatarUrl,
		isFirstLogin
	});
};
/**
* POST /_emdash/api/auth/me
*
* Mark that the user has seen the welcome modal.
*/
const POST = async ({ request, locals }) => {
	const { user, emdash } = locals;
	if (!user) return apiError("NOT_AUTHENTICATED", "Not authenticated", 401);
	if (!emdash) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	const body = await parseBody(request, authMeActionBody);
	if (isParseError(body)) return body;
	if (body.action === "dismissWelcome") try {
		await new UserRepository(emdash.db).update(user.id, { data: {
			...user.data,
			welcomeDismissed: true
		} });
		return apiSuccess({ success: true });
	} catch (error) {
		return handleError(error, "Failed to dismiss welcome", "WELCOME_DISMISS_ERROR");
	}
	return apiError("UNKNOWN_ACTION", "Unknown action", 400);
};

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