fix: empty SITE_PASSWORD

This commit is contained in:
hamster1963 2024-10-20 16:19:42 +08:00
parent 20ed4a819f
commit b7e403756a
4 changed files with 8 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import Footer from "@/app/[locale]/(main)/footer";
import Header from "@/app/[locale]/(main)/header"; import Header from "@/app/[locale]/(main)/header";
import { auth } from "@/auth"; import { auth } from "@/auth";
import { SignIn } from "@/components/sign-in"; import { SignIn } from "@/components/sign-in";
import getEnv from "@/lib/env-entry";
import React from "react"; import React from "react";
type DashboardProps = { type DashboardProps = {
@ -9,7 +10,7 @@ type DashboardProps = {
}; };
export default async function MainLayout({ children }: DashboardProps) { export default async function MainLayout({ children }: DashboardProps) {
const session = await auth() const session = await auth()
if (!session) return <SignIn /> if (!session && getEnv("SITE_PASSWORD")) return <SignIn />
return ( return (
<div className="flex min-h-screen w-full flex-col"> <div className="flex min-h-screen w-full flex-col">

View File

@ -2,6 +2,7 @@ import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import { GetServerDetail } from "@/lib/serverFetch"; import { GetServerDetail } from "@/lib/serverFetch";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { auth } from "@/auth" import { auth } from "@/auth"
import getEnv from "@/lib/env-entry";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@ -12,7 +13,7 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) { 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 }); return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
} }

View File

@ -1,5 +1,6 @@
import { ServerMonitorChart } from "@/app/[locale]/types/nezha-api"; import { ServerMonitorChart } from "@/app/[locale]/types/nezha-api";
import { auth } from "@/auth"; import { auth } from "@/auth";
import getEnv from "@/lib/env-entry";
import { GetServerMonitor } from "@/lib/serverFetch"; import { GetServerMonitor } from "@/lib/serverFetch";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
@ -12,11 +13,10 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) { 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 }); return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
} }
const { searchParams } = new URL(req.url); const { searchParams } = new URL(req.url);
const server_id = searchParams.get("server_id"); const server_id = searchParams.get("server_id");
if (!server_id) { if (!server_id) {

View File

@ -1,5 +1,6 @@
import { ServerApi } from "@/app/[locale]/types/nezha-api"; import { ServerApi } from "@/app/[locale]/types/nezha-api";
import { auth } from "@/auth"; import { auth } from "@/auth";
import getEnv from "@/lib/env-entry";
import { GetNezhaData } from "@/lib/serverFetch"; import { GetNezhaData } from "@/lib/serverFetch";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
@ -12,7 +13,7 @@ interface NezhaDataResponse {
export const GET = auth(async function GET(req) { 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 }); return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
} }