fix: prevent settings save from deleting API keys

When saving settings, empty sensitive fields (pagespeedApiKey,
globalpingApiKey, systemEmailPassword) were sent as "" to the server,
which treated them as $unset operations — deleting the stored keys.

Now the form omits these fields from the payload when they're already
set and haven't been explicitly reset by the user.
This commit is contained in:
gorkem-bwl committed 2026-02-19 11:04:21 -05:00
1 parent 1966134647
commit 7f9d2f275e
1 file changed
+12
+12
View File
@@ -112,6 +112,18 @@ const Settings = () => {
})
);
// Don't send empty sensitive fields when the key is already set and
// hasn't been explicitly reset — otherwise the backend $unsets them
if (isApiKeySet && !apiKeyHasBeenReset && !toSubmit.pagespeedApiKey) {
delete toSubmit.pagespeedApiKey;
}
if (isGlobalpingKeySet && !globalpingKeyHasBeenReset && !toSubmit.globalpingApiKey) {
delete toSubmit.globalpingApiKey;
}
if (isEmailPasswordSet && !emailPasswordHasBeenReset && !toSubmit.systemEmailPassword) {
delete toSubmit.systemEmailPassword;
}
saveSettings(toSubmit);
};