diff --git a/src/app/api/eterra/sync-county/route.ts b/src/app/api/eterra/sync-county/route.ts index abfff02..e01159c 100644 --- a/src/app/api/eterra/sync-county/route.ts +++ b/src/app/api/eterra/sync-county/route.ts @@ -20,6 +20,7 @@ import { enrichFeatures } from "@/modules/parcel-sync/services/enrich-service"; import { EterraClient } from "@/modules/parcel-sync/services/eterra-client"; import { checkEterraHealthNow } from "@/modules/parcel-sync/services/eterra-health"; import { createAppNotification } from "@/core/notifications/app-notifications"; +import { getSessionCredentials } from "@/modules/parcel-sync/services/session-store"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; @@ -28,15 +29,6 @@ export const dynamic = "force-dynamic"; const g = globalThis as { __countySyncRunning?: string }; export async function POST(req: Request) { - const username = process.env.ETERRA_USERNAME ?? ""; - const password = process.env.ETERRA_PASSWORD ?? ""; - if (!username || !password) { - return Response.json( - { error: "ETERRA_USERNAME / ETERRA_PASSWORD nu sunt configurate" }, - { status: 500 }, - ); - } - let body: { county?: string }; try { body = (await req.json()) as { county?: string }; @@ -44,6 +36,16 @@ export async function POST(req: Request) { return Response.json({ error: "Body invalid" }, { status: 400 }); } + const session = getSessionCredentials(); + const username = String(session?.username || process.env.ETERRA_USERNAME || "").trim(); + const password = String(session?.password || process.env.ETERRA_PASSWORD || "").trim(); + if (!username || !password) { + return Response.json( + { error: "Credentiale lipsa — conecteaza-te la eTerra mai intai." }, + { status: 401 }, + ); + } + const county = body.county?.trim(); if (!county) { return Response.json({ error: "Judetul lipseste" }, { status: 400 });