用户系统

This commit is contained in:
2026-04-15 00:21:43 +08:00
parent 97bbb3f306
commit 47c0863bab
23 changed files with 1640 additions and 56 deletions

View File

@@ -0,0 +1,36 @@
"use client";
import { useEffect, type ReactNode } from "react";
import { usePathname, useRouter } from "next/navigation";
import { useAuth } from "./auth-context";
const PUBLIC_PATHS = ["/login"];
export function AuthGuard({ children }: { children: ReactNode }) {
const { isAuthenticated, isLoading } = useAuth();
const pathname = usePathname();
const router = useRouter();
const isPublic = PUBLIC_PATHS.includes(pathname);
useEffect(() => {
if (isLoading) return;
if (!isAuthenticated && !isPublic) {
router.replace("/login");
}
}, [isAuthenticated, isLoading, isPublic, router]);
if (isLoading) {
return (
<div className="h-screen flex items-center justify-center bg-[var(--bg-primary)]">
<div className="text-[var(--text-secondary)] text-sm">...</div>
</div>
);
}
if (!isAuthenticated && !isPublic) {
return null;
}
return <>{children}</>;
}