@@ -4,6 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { routing } from "@/i18n/routing";
|
||||
import { toInternalAdminPath } from "@/lib/admin-routing";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getLocalizedPath } from "@/lib/locale";
|
||||
import { setMaintenanceMode } from "@/lib/app-config";
|
||||
@@ -11,7 +12,7 @@ import { setMaintenanceMode } from "@/lib/app-config";
|
||||
function ensureAdmin() {
|
||||
if (!isAdminAuthenticated()) {
|
||||
clearAdminSessionCookie();
|
||||
redirect("/root");
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ export async function updateMaintenanceModeAction(formData: FormData) {
|
||||
ensureAdmin();
|
||||
|
||||
const nextValue = formData.get("enabled") === "true";
|
||||
const redirectPath = String(formData.get("redirectPath") ?? "/root");
|
||||
const redirectPath = String(formData.get("redirectPath") ?? "/");
|
||||
const redirectUrl = new URL(redirectPath, "http://localhost");
|
||||
redirectUrl.searchParams.set(
|
||||
"success",
|
||||
@@ -29,9 +30,9 @@ export async function updateMaintenanceModeAction(formData: FormData) {
|
||||
await setMaintenanceMode(nextValue);
|
||||
revalidatePath("/", "layout");
|
||||
revalidatePath("/coming-soon");
|
||||
revalidatePath("/root");
|
||||
revalidatePath("/root/maintenance");
|
||||
revalidatePath(redirectPath);
|
||||
revalidatePath(toInternalAdminPath("/"));
|
||||
revalidatePath(toInternalAdminPath("/maintenance"));
|
||||
revalidatePath(toInternalAdminPath(redirectUrl.pathname));
|
||||
|
||||
for (const appLocale of routing.locales) {
|
||||
revalidatePath(getLocalizedPath(appLocale), "layout");
|
||||
|
||||
Reference in New Issue
Block a user