mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-19 14:31:56 +08:00
refactor: Remove NavBarWrapper and update home page navigation
This commit is contained in:
parent
263f62033f
commit
a2964a177b
@ -18,12 +18,12 @@ import {
|
|||||||
TypographyLead,
|
TypographyLead,
|
||||||
TypographyMuted,
|
TypographyMuted,
|
||||||
} from "@/components/ui/typography";
|
} from "@/components/ui/typography";
|
||||||
import { NavBarWrapper } from "@/components/layout/nav-bar-wrapper";
|
import { NavBar } from "@/components/layout/nav-bar";
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen flex-col">
|
<div className="flex min-h-screen flex-col">
|
||||||
<NavBarWrapper />
|
<NavBar />
|
||||||
<main className="flex-1">
|
<main className="flex-1">
|
||||||
<Section className="pb-0">
|
<Section className="pb-0">
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
import { getCurrentUser } from "@/lib/session";
|
import { getCurrentUser } from "@/lib/session";
|
||||||
|
import { AuthStateSync } from "@/components/auth/auth-state-sync";
|
||||||
|
|
||||||
export default async function AuthLayout({
|
export default async function AuthLayout({
|
||||||
children,
|
children,
|
||||||
@ -15,10 +16,13 @@ export default async function AuthLayout({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
<AuthStateSync />
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen">
|
||||||
<div className="flex h-screen w-screen flex-col items-center justify-center">
|
<div className="flex h-screen w-screen flex-col items-center justify-center">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
20
src/components/auth/auth-state-sync.tsx
Normal file
20
src/components/auth/auth-state-sync.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
|
|
||||||
|
export function AuthStateSync() {
|
||||||
|
const { data: session, status, update } = useSession();
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 当状态从"loading"变为"authenticated"时,强制刷新路由
|
||||||
|
if (status === "authenticated" && session?.user) {
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
}, [status, session]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { usePathname, useRouter } from "next/navigation";
|
|
||||||
|
|
||||||
import { NavBar } from "./nav-bar";
|
|
||||||
|
|
||||||
export function NavBarWrapper() {
|
|
||||||
const router = useRouter();
|
|
||||||
const pathname = usePathname();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (pathname?.startsWith("/dashboard") || pathname?.startsWith("/admin")) {
|
|
||||||
router.refresh();
|
|
||||||
}
|
|
||||||
}, [pathname, router]);
|
|
||||||
|
|
||||||
return <NavBar />;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user