diff --git a/app/(main)/layout.tsx b/app/(main)/layout.tsx index 9df1909..8df46a4 100644 --- a/app/(main)/layout.tsx +++ b/app/(main)/layout.tsx @@ -8,16 +8,24 @@ import React from "react"; type DashboardProps = { children: React.ReactNode; }; -export default async function MainLayout({ children }: DashboardProps) { - const session = await auth(); - +export default function MainLayout({ children }: DashboardProps) { return (
- {!session && getEnv("SitePassword") ? : children} + {children}
); } + +async function AuthProtected({ children }: DashboardProps) { + if (getEnv("SitePassword")) { + const session = await auth(); + if (!session) { + return ; + } + } + return children; +} diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts index 91ee0e6..ead6722 100644 --- a/app/api/detail/route.ts +++ b/app/api/detail/route.ts @@ -12,10 +12,11 @@ interface ResError extends Error { } export async function GET(req: NextRequest) { - const session = await auth(); - - if (!session && getEnv("SitePassword")) { - redirect("/"); + if (getEnv("SitePassword")) { + const session = await auth(); + if (!session) { + redirect("/"); + } } const { searchParams } = new URL(req.url); diff --git a/app/api/monitor/route.ts b/app/api/monitor/route.ts index beb8326..82a4ceb 100644 --- a/app/api/monitor/route.ts +++ b/app/api/monitor/route.ts @@ -12,14 +12,16 @@ interface ResError extends Error { } export async function GET(req: NextRequest) { - const session = await auth(); - - if (!session && getEnv("SitePassword")) { - redirect("/"); + if (getEnv("SitePassword")) { + const session = await auth(); + if (!session) { + redirect("/"); + } } const { searchParams } = new URL(req.url); const server_id = searchParams.get("server_id"); + if (!server_id) { return NextResponse.json( { error: "server_id is required" }, diff --git a/app/api/server/route.ts b/app/api/server/route.ts index f54fdec..5c97021 100644 --- a/app/api/server/route.ts +++ b/app/api/server/route.ts @@ -12,10 +12,11 @@ interface ResError extends Error { } export async function GET() { - const session = await auth(); - - if (!session && getEnv("SitePassword")) { - redirect("/"); + if (getEnv("SitePassword")) { + const session = await auth(); + if (!session) { + redirect("/"); + } } try { diff --git a/lib/env-entry.ts b/lib/env-entry.ts index 258c632..caf79fc 100644 --- a/lib/env-entry.ts +++ b/lib/env-entry.ts @@ -1,8 +1,8 @@ import { env } from "next-runtime-env"; export default function getEnv(key: string) { - if (key.startsWith("NEXT_PUBLIC_")) { - return env(key); - } - return process.env[key]; + if (key.startsWith("NEXT_PUBLIC_")) { + return env(key); + } + return process.env[key]; } diff --git a/package.json b/package.json index 0208f46..520ba39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nezha-dash", - "version": "1.2.4", + "version": "1.2.5", "private": true, "scripts": { "dev": "next dev -p 3020",