diff --git a/app/[locale]/(main)/layout.tsx b/app/[locale]/(main)/layout.tsx index e60a237..e11be35 100644 --- a/app/[locale]/(main)/layout.tsx +++ b/app/[locale]/(main)/layout.tsx @@ -3,7 +3,6 @@ import Header from "@/app/[locale]/(main)/header"; import { auth } from "@/auth"; import { SignIn } from "@/components/SignIn"; import getEnv from "@/lib/env-entry"; -import { redirect } from "next/navigation"; import React from "react"; type DashboardProps = { diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts index 130db59..f9aeec2 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 { auth } from "@/auth"; import getEnv from "@/lib/env-entry"; import { GetServerDetail } from "@/lib/serverFetch"; +import { redirect } from "next/navigation"; import { NextResponse } from "next/server"; export const runtime = 'edge'; @@ -15,7 +16,7 @@ interface NezhaDataResponse { export const GET = auth(async function GET(req) { if (!req.auth && getEnv("SitePassword")) { - return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + redirect("/api/auth/signin"); } const { searchParams } = new URL(req.url); diff --git a/app/api/monitor/route.ts b/app/api/monitor/route.ts index 5efa687..e2dc821 100644 --- a/app/api/monitor/route.ts +++ b/app/api/monitor/route.ts @@ -2,6 +2,7 @@ import { ServerMonitorChart } from "@/app/[locale]/types/nezha-api"; import { auth } from "@/auth"; import getEnv from "@/lib/env-entry"; import { GetServerMonitor } from "@/lib/serverFetch"; +import { redirect } from "next/navigation"; import { NextResponse } from "next/server"; export const runtime = "edge"; @@ -15,7 +16,7 @@ interface NezhaDataResponse { export const GET = auth(async function GET(req) { if (!req.auth && getEnv("SitePassword")) { - return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + redirect("/api/auth/signin"); } const { searchParams } = new URL(req.url); diff --git a/app/api/server/route.ts b/app/api/server/route.ts index 48bfe8a..71bea27 100644 --- a/app/api/server/route.ts +++ b/app/api/server/route.ts @@ -2,6 +2,7 @@ import { ServerApi } from "@/app/[locale]/types/nezha-api"; import { auth } from "@/auth"; import getEnv from "@/lib/env-entry"; import { GetNezhaData } from "@/lib/serverFetch"; +import { redirect } from "next/navigation"; import { NextResponse } from "next/server"; export const dynamic = "force-dynamic"; @@ -15,7 +16,7 @@ interface NezhaDataResponse { export const GET = auth(async function GET(req) { if (!req.auth && getEnv("SitePassword")) { - return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + redirect("/api/auth/signin"); } const response = (await GetNezhaData()) as NezhaDataResponse;