From 19d7ac5862d02e3285693587b38a95be01cba22c Mon Sep 17 00:00:00 2001 From: sijinhui Date: Fri, 26 Apr 2024 11:03:13 +0800 Subject: [PATCH] test loading --- app/api/{ => admin}/charts/route.ts | 0 app/components/home.tsx | 3 +++ middleware.ts | 7 +++++++ 3 files changed, 10 insertions(+) rename app/api/{ => admin}/charts/route.ts (100%) diff --git a/app/api/charts/route.ts b/app/api/admin/charts/route.ts similarity index 100% rename from app/api/charts/route.ts rename to app/api/admin/charts/route.ts diff --git a/app/components/home.tsx b/app/components/home.tsx index ac9f59b67..146556a47 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -1,5 +1,7 @@ "use client"; +import { useSession } from "next-auth/react"; + require("../polyfill"); import { useState, useEffect } from "react"; @@ -192,6 +194,7 @@ export function useLoadData() { } export function Home() { + // const { status } = useSession({ required: true }) useSwitchTheme(); useLoadData(); useHtmlLang(); diff --git a/middleware.ts b/middleware.ts index 7f5acf1f5..e16298003 100644 --- a/middleware.ts +++ b/middleware.ts @@ -15,6 +15,11 @@ export default async function middleware(req: NextRequest) { return NextResponse.redirect(new URL(path.replace('/app', ''), req.url), 301); } + // 如果是主页,交给主页判断,这里判断会影响性能 + // if (path == "/") { + // return NextResponse.next() + // } + const session = await getToken({ req }); const isUser = await VerifiedUser(session); const isAdminUser = await VerifiedAdminUser(session); @@ -33,6 +38,8 @@ export default async function middleware(req: NextRequest) { return NextResponse.redirect(new URL("/", req.url)) } + + if (path == '/login') { return NextResponse.rewrite( new URL(`/app${path}`, req.url),