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,