Merge branch 'hamster1963:main' into main

This commit is contained in:
kattocloud 2024-11-06 20:12:17 +08:00 committed by GitHub
commit d43f4c8ebb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 21 deletions

View File

@ -8,16 +8,24 @@ import React from "react";
type DashboardProps = { type DashboardProps = {
children: React.ReactNode; children: React.ReactNode;
}; };
export default async function MainLayout({ children }: DashboardProps) { export default function MainLayout({ children }: DashboardProps) {
const session = await auth();
return ( return (
<div className="flex min-h-screen w-full flex-col"> <div className="flex min-h-screen w-full flex-col">
<main className="flex min-h-[calc(100vh_-_theme(spacing.16))] flex-1 flex-col gap-4 bg-background p-4 md:p-10 md:pt-8"> <main className="flex min-h-[calc(100vh_-_theme(spacing.16))] flex-1 flex-col gap-4 bg-background p-4 md:p-10 md:pt-8">
<Header /> <Header />
{!session && getEnv("SitePassword") ? <SignIn /> : children} <AuthProtected>{children}</AuthProtected>
<Footer /> <Footer />
</main> </main>
</div> </div>
); );
} }
async function AuthProtected({ children }: DashboardProps) {
if (getEnv("SitePassword")) {
const session = await auth();
if (!session) {
return <SignIn />;
}
}
return children;
}

View File

@ -12,11 +12,12 @@ interface ResError extends Error {
} }
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
if (getEnv("SitePassword")) {
const session = await auth(); const session = await auth();
if (!session) {
if (!session && getEnv("SitePassword")) {
redirect("/"); redirect("/");
} }
}
const { searchParams } = new URL(req.url); const { searchParams } = new URL(req.url);
const server_id = searchParams.get("server_id"); const server_id = searchParams.get("server_id");

View File

@ -12,14 +12,16 @@ interface ResError extends Error {
} }
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
if (getEnv("SitePassword")) {
const session = await auth(); const session = await auth();
if (!session) {
if (!session && getEnv("SitePassword")) {
redirect("/"); redirect("/");
} }
}
const { searchParams } = new URL(req.url); const { searchParams } = new URL(req.url);
const server_id = searchParams.get("server_id"); const server_id = searchParams.get("server_id");
if (!server_id) { if (!server_id) {
return NextResponse.json( return NextResponse.json(
{ error: "server_id is required" }, { error: "server_id is required" },

View File

@ -12,11 +12,12 @@ interface ResError extends Error {
} }
export async function GET() { export async function GET() {
if (getEnv("SitePassword")) {
const session = await auth(); const session = await auth();
if (!session) {
if (!session && getEnv("SitePassword")) {
redirect("/"); redirect("/");
} }
}
try { try {
const data = await GetNezhaData(); const data = await GetNezhaData();

View File

@ -1,6 +1,6 @@
{ {
"name": "nezha-dash", "name": "nezha-dash",
"version": "1.2.4", "version": "1.2.5",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3020", "dev": "next dev -p 3020",