mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
perf(layout): refactor auth check
This commit is contained in:
parent
a8cbf9589a
commit
b123ad9f3e
@ -8,16 +8,24 @@ import React from "react";
|
||||
type DashboardProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
export default async function MainLayout({ children }: DashboardProps) {
|
||||
const session = await auth();
|
||||
|
||||
export default function MainLayout({ children }: DashboardProps) {
|
||||
return (
|
||||
<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">
|
||||
<Header />
|
||||
{!session && getEnv("SitePassword") ? <SignIn /> : children}
|
||||
<AuthProtected>{children}</AuthProtected>
|
||||
<Footer />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
async function AuthProtected({ children }: DashboardProps) {
|
||||
if (getEnv("SitePassword")) {
|
||||
const session = await auth();
|
||||
if (!session) {
|
||||
return <SignIn />;
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
@ -12,11 +12,12 @@ interface ResError extends Error {
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
if (getEnv("SitePassword")) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session && getEnv("SitePassword")) {
|
||||
if (!session) {
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const server_id = searchParams.get("server_id");
|
||||
|
@ -12,14 +12,16 @@ interface ResError extends Error {
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
if (getEnv("SitePassword")) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session && getEnv("SitePassword")) {
|
||||
if (!session) {
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const server_id = searchParams.get("server_id");
|
||||
|
||||
if (!server_id) {
|
||||
return NextResponse.json(
|
||||
{ error: "server_id is required" },
|
||||
|
@ -12,11 +12,12 @@ interface ResError extends Error {
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
if (getEnv("SitePassword")) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session && getEnv("SitePassword")) {
|
||||
if (!session) {
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await GetNezhaData();
|
||||
|
Loading…
Reference in New Issue
Block a user