import { Navigate, useLocation } from 'react-router-dom'; import { getPartnerProfile, hasPartnerWxSession } from '../lib/api'; import { usePartnerSession } from '../contexts/PartnerSessionContext'; import { partnerHomePath } from '../lib/partnerAccess'; const PUBLIC_PATHS = new Set(['/login', '/legal/user-agreement', '/legal/privacy-policy']); export default function AuthGate({ children }: { children: React.ReactNode }) { const { ready, authenticated, account } = usePartnerSession(); const location = useLocation(); if (!ready) { return
加载中...
; } if (authenticated && location.pathname === '/login') { return ; } if (!authenticated && !PUBLIC_PATHS.has(location.pathname)) { const profile = getPartnerProfile(); if (profile && hasPartnerWxSession() && profile.hasWechat) { return ; } return ; } return <>{children}; }