fix admin save state architecture
This commit is contained in:
@@ -5,6 +5,7 @@ import { redirect } from "next/navigation";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect";
|
||||
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { isCheckedFormValue } from "@/lib/form-data";
|
||||
import {
|
||||
getMailSettings,
|
||||
updateMailSettings,
|
||||
@@ -53,7 +54,7 @@ function parseMailSettingsFormData(
|
||||
smtp: {
|
||||
host,
|
||||
port: parsePort(portValue || String(existingSettings.smtp.port)),
|
||||
secure: formData.get("smtpSecure") === "on",
|
||||
secure: isCheckedFormValue(formData.get("smtpSecure")),
|
||||
username,
|
||||
password: password.trim() ? password : existingSettings.smtp.password,
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import { redirect } from "next/navigation";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect";
|
||||
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { isCheckedFormValue } from "@/lib/form-data";
|
||||
import {
|
||||
getContactProtectionSettings,
|
||||
updateContactProtectionSettings,
|
||||
@@ -39,10 +40,10 @@ function parseContactProtectionFormData(
|
||||
formData: FormData,
|
||||
existingSettings: ContactProtectionSettings,
|
||||
): ContactProtectionSettings {
|
||||
const turnstileEnabled = formData.get("turnstileEnabled") === "on";
|
||||
const turnstileEnabled = isCheckedFormValue(formData.get("turnstileEnabled"));
|
||||
const turnstileSiteKey = String(formData.get("turnstileSiteKey") ?? "").trim();
|
||||
const turnstileSecretKey = String(formData.get("turnstileSecretKey") ?? "");
|
||||
const rateLimitEnabled = formData.get("contactRateLimitEnabled") === "on";
|
||||
const rateLimitEnabled = isCheckedFormValue(formData.get("contactRateLimitEnabled"));
|
||||
|
||||
if (turnstileEnabled && !turnstileSiteKey) {
|
||||
throw new Error("Turnstile site key is required when Turnstile is enabled.");
|
||||
|
||||
Reference in New Issue
Block a user