fix(flexoptix-sync): empty FLEXOPTIX_API_TOKEN string short-circuited bearer login

Root cause of the persistent sync:flexoptix-catalog HTTP 401: line 397 used
'?? null' which only coerces null/undefined. With FLEXOPTIX_API_TOKEN='' (empty
string set in .env), token stayed '' and line 485's 'token ?? getBearerToken()'
returned '' instead of performing the username/password login — sending an empty
'Bearer ' header that the products endpoint rejected with 401.

Fix: '|| null' coerces empty string to null so the bearer-login fallback fires.
Verified: sync now completes (username/password -> customer token -> products 200,
3 products/price/stock writes on limit=50). Credentials were correct all along.
This commit is contained in:
Rene Fichtmueller 2026-06-06 17:06:22 +00:00
parent 82934d3e0a
commit 2432c0ddfc

View File

@ -394,7 +394,7 @@ function validateEnv(): { baseUrl: string; username: string | null; password: st
if (!baseUrl) { if (!baseUrl) {
throw new Error("FLEXOPTIX_API_BASE_URL is required for Flexoptix API sync"); throw new Error("FLEXOPTIX_API_BASE_URL is required for Flexoptix API sync");
} }
const token = process.env["FLEXOPTIX_API_TOKEN"]?.trim() ?? null; const token = process.env["FLEXOPTIX_API_TOKEN"]?.trim() || null; // empty string -> null so bearer-login fallback fires
const username = process.env["FLEXOPTIX_API_USERNAME"]?.trim() ?? null; const username = process.env["FLEXOPTIX_API_USERNAME"]?.trim() ?? null;
const password = process.env["FLEXOPTIX_API_PASSWORD"]?.trim() ?? null; const password = process.env["FLEXOPTIX_API_PASSWORD"]?.trim() ?? null;
if (!token && (!username || !password)) { if (!token && (!username || !password)) {