"use client" import { useEffect } from 'react' import { useRouter, usePathname } from 'next/navigation' import { useAuth } from '@/hooks/useAuth' // 不需要登录的公共页面路径 const PUBLIC_PATHS = [ '/login', '/register', '/forgot-password', '/reset-password', '/404', '/500' ] export function AuthCheck({ children }: { children: React.ReactNode }) { const router = useRouter() const pathname = usePathname() const { isAuthenticated, isLoading } = useAuth() useEffect(() => { if (!isLoading && !isAuthenticated && !PUBLIC_PATHS.includes(pathname)) { // 保存当前URL,登录后可以重定向回来 const returnUrl = encodeURIComponent(window.location.href) router.push(`/login?returnUrl=${returnUrl}`) } }, [isAuthenticated, isLoading, pathname, router]) if (isLoading) { return (