(() => { });
useEffect(() => {
savedCallback.current = callback;
});
diff --git a/app/[locale]/(main)/page.tsx b/app/[locale]/(main)/page.tsx
index 79b4bd9..f0d48e0 100644
--- a/app/[locale]/(main)/page.tsx
+++ b/app/[locale]/(main)/page.tsx
@@ -1,13 +1,21 @@
+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 function Home({
+export default async function Home({
params: { locale },
}: {
params: { locale: string };
}) {
unstable_setRequestLocale(locale);
+
+ const session = await auth()
+ if (!session) return
+
+
+
return (
diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx
index 4671348..2b2864f 100644
--- a/app/[locale]/layout.tsx
+++ b/app/[locale]/layout.tsx
@@ -13,6 +13,7 @@ import { Inter as FontSans } from "next/font/google";
import React from "react";
import "/node_modules/flag-icons/css/flag-icons.min.css";
+import { auth } from "@/auth";
const fontSans = FontSans({
subsets: ["latin"],
@@ -54,6 +55,7 @@ export default function LocaleLayout({
unstable_setRequestLocale(locale);
const messages = useMessages();
+
return (
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts
new file mode 100644
index 0000000..0cf1408
--- /dev/null
+++ b/app/api/auth/[...nextauth]/route.ts
@@ -0,0 +1,2 @@
+import { handlers } from "@/auth" // Referring to the auth.ts we just created
+export const { GET, POST } = handlers
\ No newline at end of file
diff --git a/app/api/detail/route.ts b/app/api/detail/route.ts
index b0f8bc1..c9a23ea 100644
--- a/app/api/detail/route.ts
+++ b/app/api/detail/route.ts
@@ -1,6 +1,7 @@
import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import { GetServerDetail } from "@/lib/serverFetch";
import { NextResponse } from "next/server";
+import { auth } from "@/auth"
export const dynamic = "force-dynamic";
@@ -9,7 +10,11 @@ interface NezhaDataResponse {
data?: NezhaAPISafe;
}
-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 +31,4 @@ export async function GET(req: Request) {
return NextResponse.json({ error: response.error }, { status: 400 });
}
return NextResponse.json(response, { status: 200 });
-}
+});
diff --git a/auth.ts b/auth.ts
new file mode 100644
index 0000000..a912a4e
--- /dev/null
+++ b/auth.ts
@@ -0,0 +1,18 @@
+import NextAuth from "next-auth"
+import Credentials from "next-auth/providers/credentials"
+
+export const { handlers, signIn, signOut, auth } = NextAuth({
+ providers: [
+ Credentials({
+ credentials: {
+ password: {},
+ },
+ authorize: async (credentials) => {
+ if (credentials.password === "123456") {
+ return { id: "1", name: "John Doe" }
+ }
+ return null
+ },
+ }),
+ ],
+})
\ No newline at end of file
diff --git a/bun.lockb b/bun.lockb
index e99d417..6cbf07d 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/components/sign-in.tsx b/components/sign-in.tsx
new file mode 100644
index 0000000..0bc181c
--- /dev/null
+++ b/components/sign-in.tsx
@@ -0,0 +1,18 @@
+import { signIn } from "@/auth"
+
+export function SignIn() {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/middleware.ts b/middleware.ts
index 92342ad..fa0386d 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -3,6 +3,8 @@ import createMiddleware from "next-intl/middleware";
import { defaultLocale, locales } from "./i18n-metadata";
+// export { auth as middleware } from "@/auth"
+
export default createMiddleware({
// A list of all locales that are supported
locales: locales,
diff --git a/package.json b/package.json
index e94e7b2..76c090f 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"lucide-react": "^0.451.0",
"luxon": "^3.5.0",
"next": "^14.2.15",
+ "next-auth": "^5.0.0-beta.25",
"next-intl": "^3.21.1",
"next-runtime-env": "^3.2.2",
"next-themes": "^0.3.0",