fix ops local admin redirects

This commit is contained in:
2569718930@qq.com
2026-06-14 22:44:02 +08:00
parent 8bbe8f74c1
commit a9e9eed2f1
6 changed files with 119 additions and 2 deletions
+11 -1
View File
@@ -1,11 +1,14 @@
import { cookies } from "next/headers";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";
import { isLocalOpsAccessHost } from "@/lib/ops-local-access";
import {
createSupabaseServerClient,
hasSupabaseServerEnv,
hasSupabaseSessionCookieValues,
} from "@/lib/supabase/server";
const LOCAL_DEV_OPS_EMAIL = "local-dev@polyweather.local";
function parseAdminEmails() {
return String(process.env.POLYWEATHER_OPS_ADMIN_EMAILS || "")
.split(",")
@@ -14,6 +17,13 @@ function parseAdminEmails() {
}
export async function requireOpsAdmin(nextPath = "/ops") {
const headerStore = await headers();
const requestHost =
headerStore.get("x-forwarded-host") || headerStore.get("host") || "";
if (isLocalOpsAccessHost(requestHost)) {
return { email: LOCAL_DEV_OPS_EMAIL };
}
const allowedEmails = parseAdminEmails();
if (!allowedEmails.length || !hasSupabaseServerEnv()) {
redirect("/");