diff --git a/app/[locale]/(main)/header.tsx b/app/[locale]/(main)/header.tsx index 47cf6e1..a7d9ec7 100644 --- a/app/[locale]/(main)/header.tsx +++ b/app/[locale]/(main)/header.tsx @@ -10,9 +10,8 @@ import { useLocale } from "next-intl"; import Image from "next/image"; import { useRouter } from "next/navigation"; import React, { useEffect, useRef, useState } from "react"; -import { auth } from "@/auth"; -async function Header() { +function Header() { const t = useTranslations("Header"); const customLogo = getEnv("NEXT_PUBLIC_CustomLogo"); const customTitle = getEnv("NEXT_PUBLIC_CustomTitle"); @@ -21,11 +20,6 @@ async function Header() { const router = useRouter(); const locale = useLocale(); - const session = await auth(); - - if (session) { - console.log(session); - } return (
diff --git a/app/[locale]/(main)/layout.tsx b/app/[locale]/(main)/layout.tsx index 84bd06e..4a1c101 100644 --- a/app/[locale]/(main)/layout.tsx +++ b/app/[locale]/(main)/layout.tsx @@ -1,11 +1,16 @@ 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 React from "react"; type DashboardProps = { children: React.ReactNode; }; -export default function MainLayout({ children }: DashboardProps) { +export default async function MainLayout({ children }: DashboardProps) { + const session = await auth() + if (!session) return + return (
diff --git a/app/[locale]/(main)/page.tsx b/app/[locale]/(main)/page.tsx index f0d48e0..0e568e6 100644 --- a/app/[locale]/(main)/page.tsx +++ b/app/[locale]/(main)/page.tsx @@ -1,21 +1,14 @@ -import { auth } from "@/auth"; import ServerList from "@/components/ServerList"; import ServerOverview from "@/components/ServerOverview"; -import { SignIn } from "@/components/sign-in"; import { unstable_setRequestLocale } from "next-intl/server"; -export default async function Home({ +export default function Home({ params: { locale }, }: { params: { locale: string }; }) { unstable_setRequestLocale(locale); - const session = await auth() - if (!session) return - - - return (
diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts index c9a23ea..5361e90 100644 --- a/app/api/detail/route.ts +++ b/app/api/detail/route.ts @@ -12,8 +12,9 @@ interface NezhaDataResponse { export const GET = auth(async function GET(req) { - if (!req.auth) + if (!req.auth) { return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + } const { searchParams } = new URL(req.url); const server_id = searchParams.get("server_id"); diff --git a/app/api/monitor/route.ts b/app/api/monitor/route.ts index e03fe89..9a7f17c 100644 --- a/app/api/monitor/route.ts +++ b/app/api/monitor/route.ts @@ -1,4 +1,5 @@ import { ServerMonitorChart } from "@/app/[locale]/types/nezha-api"; +import { auth } from "@/auth"; import { GetServerMonitor } from "@/lib/serverFetch"; import { NextResponse } from "next/server"; @@ -9,7 +10,13 @@ interface NezhaDataResponse { data?: ServerMonitorChart; } -export async function GET(req: Request) { +export const GET = auth(async function GET(req) { + + if (!req.auth) { + return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + } + + const { searchParams } = new URL(req.url); const server_id = searchParams.get("server_id"); if (!server_id) { @@ -26,4 +33,4 @@ export async function GET(req: Request) { return NextResponse.json({ error: response.error }, { status: 400 }); } return NextResponse.json(response, { status: 200 }); -} +}); diff --git a/app/api/server/route.ts b/app/api/server/route.ts index e34a83c..7a6176a 100644 --- a/app/api/server/route.ts +++ b/app/api/server/route.ts @@ -1,4 +1,5 @@ import { ServerApi } from "@/app/[locale]/types/nezha-api"; +import { auth } from "@/auth"; import { GetNezhaData } from "@/lib/serverFetch"; import { NextResponse } from "next/server"; @@ -9,11 +10,16 @@ interface NezhaDataResponse { data?: ServerApi; } -export async function GET(_: Request) { +export const GET = auth(async function GET(req) { + + if (!req.auth) { + return NextResponse.json({ message: "Not authenticated" }, { status: 401 }); + } + const response = (await GetNezhaData()) as NezhaDataResponse; if (response.error) { console.log(response.error); return NextResponse.json({ error: response.error }, { status: 400 }); } return NextResponse.json(response, { status: 200 }); -} +}); diff --git a/auth.ts b/auth.ts index a912a4e..a908388 100644 --- a/auth.ts +++ b/auth.ts @@ -1,15 +1,17 @@ import NextAuth from "next-auth" import Credentials from "next-auth/providers/credentials" +import getEnv from "./lib/env-entry" export const { handlers, signIn, signOut, auth } = NextAuth({ + secret:"this_is_nezha_dash_web_secret", providers: [ Credentials({ credentials: { password: {}, }, authorize: async (credentials) => { - if (credentials.password === "123456") { - return { id: "1", name: "John Doe" } + if (credentials.password === getEnv("SITE_PASSWORD")) { + return { id: "0" } } return null }, diff --git a/bun.lockb b/bun.lockb index 6cbf07d..a0f7e64 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/next.config.mjs b/next.config.mjs index 86bfbf5..5713407 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -23,6 +23,11 @@ const withPWA = withPWAInit({ const nextConfig = { output: "standalone", reactStrictMode: true, + experimental: { + serverActions: { + allowedOrigins: ['*'], + }, + }, logging: { fetches: { fullUrl: true,