fix(web): correct secret field extraction in channel config payload builder

The previous `buildSavePayload` loop would skip any secret field coming
from `editConfig` that started with an underscore (like `_token`), but
relied on the loop having visited an existing secret key (like `token`)
first. When adding a new channel configuration where the `token` didn't
exist, the loop ignored the input completely, leading to a false positive
"This field is required." error in the UI.

This fix splits the payload builder into two passes: one to copy regular
fields and a separate one iterating specifically over `SECRET_FIELD_MAP`
to ensure any new secret field inputs are securely captured and saved.

Co-authored-by: TanLuong <28281768+TanLuong@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-03-26 09:04:16 +00:00
parent 5d9bbb7513
commit b05489bff4

View file

@ -95,14 +95,16 @@ function buildSavePayload(
if (key.startsWith("_")) continue if (key.startsWith("_")) continue
if (key === "enabled") continue if (key === "enabled") continue
if (key in SECRET_FIELD_MAP) { payload[key] = value
const editKey = SECRET_FIELD_MAP[key]
const incoming = asString(editConfig[editKey])
payload[key] = incoming !== "" ? incoming : value
continue
} }
payload[key] = value for (const [key, editKey] of Object.entries(SECRET_FIELD_MAP)) {
if (editKey in editConfig) {
const incoming = asString(editConfig[editKey])
if (incoming !== "") {
payload[key] = incoming
}
}
} }
if (channel.name === "whatsapp_native") { if (channel.name === "whatsapp_native") {