fix(sync-county): use eTerra session credentials, not just env vars
Same pattern as sync-background: session credentials from eTerra login take priority, env vars are fallback only. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import { enrichFeatures } from "@/modules/parcel-sync/services/enrich-service";
|
|||||||
import { EterraClient } from "@/modules/parcel-sync/services/eterra-client";
|
import { EterraClient } from "@/modules/parcel-sync/services/eterra-client";
|
||||||
import { checkEterraHealthNow } from "@/modules/parcel-sync/services/eterra-health";
|
import { checkEterraHealthNow } from "@/modules/parcel-sync/services/eterra-health";
|
||||||
import { createAppNotification } from "@/core/notifications/app-notifications";
|
import { createAppNotification } from "@/core/notifications/app-notifications";
|
||||||
|
import { getSessionCredentials } from "@/modules/parcel-sync/services/session-store";
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -28,15 +29,6 @@ export const dynamic = "force-dynamic";
|
|||||||
const g = globalThis as { __countySyncRunning?: string };
|
const g = globalThis as { __countySyncRunning?: string };
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
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 };
|
let body: { county?: string };
|
||||||
try {
|
try {
|
||||||
body = (await req.json()) as { county?: string };
|
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 });
|
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();
|
const county = body.county?.trim();
|
||||||
if (!county) {
|
if (!county) {
|
||||||
return Response.json({ error: "Judetul lipseste" }, { status: 400 });
|
return Response.json({ error: "Judetul lipseste" }, { status: 400 });
|
||||||
|
|||||||
Reference in New Issue
Block a user