私域操盘手 - 移除微信号账号详情的好友列表的包裹层组件,防止标签过多页面变形

This commit is contained in:
柳清爽
2025-05-16 12:03:25 +08:00
parent 1a9a7e8442
commit b8dbd93c89
8 changed files with 162 additions and 490 deletions

View File

@@ -0,0 +1,43 @@
"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 (
<div className="flex h-screen w-screen items-center justify-center">
<div className="animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-blue-500"></div>
</div>
)
}
if (!isAuthenticated && !PUBLIC_PATHS.includes(pathname)) {
return null
}
return <>{children}</>
}