From b7e403756a6041162c46531cea55eb1701294829 Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Sun, 20 Oct 2024 16:19:42 +0800
Subject: [PATCH] fix: empty SITE_PASSWORD
---
app/[locale]/(main)/layout.tsx | 3 ++-
app/api/detail/route.ts | 3 ++-
app/api/monitor/route.ts | 4 ++--
app/api/server/route.ts | 3 ++-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/app/[locale]/(main)/layout.tsx b/app/[locale]/(main)/layout.tsx
index 4a1c101..82a15af 100644
--- a/app/[locale]/(main)/layout.tsx
+++ b/app/[locale]/(main)/layout.tsx
@@ -2,6 +2,7 @@ import Footer from "@/app/[locale]/(main)/footer";
import Header from "@/app/[locale]/(main)/header";
import { auth } from "@/auth";
import { SignIn } from "@/components/sign-in";
+import getEnv from "@/lib/env-entry";
import React from "react";
type DashboardProps = {
@@ -9,7 +10,7 @@ type DashboardProps = {
};
export default async function MainLayout({ children }: DashboardProps) {
const session = await auth()
- if (!session) return
+ if (!session && getEnv("SITE_PASSWORD")) return
return (
diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts
index 5361e90..fdc18cb 100644
--- a/app/api/detail/route.ts
+++ b/app/api/detail/route.ts
@@ -2,6 +2,7 @@ import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import { GetServerDetail } from "@/lib/serverFetch";
import { NextResponse } from "next/server";
import { auth } from "@/auth"
+import getEnv from "@/lib/env-entry";
export const dynamic = "force-dynamic";
@@ -12,7 +13,7 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) {
- if (!req.auth) {
+ if (!req.auth && getEnv("SITE_PASSWORD")) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
}
diff --git a/app/api/monitor/route.ts b/app/api/monitor/route.ts
index 9a7f17c..3f38586 100644
--- a/app/api/monitor/route.ts
+++ b/app/api/monitor/route.ts
@@ -1,5 +1,6 @@
import { ServerMonitorChart } from "@/app/[locale]/types/nezha-api";
import { auth } from "@/auth";
+import getEnv from "@/lib/env-entry";
import { GetServerMonitor } from "@/lib/serverFetch";
import { NextResponse } from "next/server";
@@ -12,11 +13,10 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) {
- if (!req.auth) {
+ if (!req.auth && getEnv("SITE_PASSWORD")) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
}
-
const { searchParams } = new URL(req.url);
const server_id = searchParams.get("server_id");
if (!server_id) {
diff --git a/app/api/server/route.ts b/app/api/server/route.ts
index 7a6176a..e6a1f99 100644
--- a/app/api/server/route.ts
+++ b/app/api/server/route.ts
@@ -1,5 +1,6 @@
import { ServerApi } from "@/app/[locale]/types/nezha-api";
import { auth } from "@/auth";
+import getEnv from "@/lib/env-entry";
import { GetNezhaData } from "@/lib/serverFetch";
import { NextResponse } from "next/server";
@@ -12,7 +13,7 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) {
- if (!req.auth) {
+ if (!req.auth && getEnv("SITE_PASSWORD")) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
}