import { Navigate, useLocation } from 'react-router-dom'; import { getStoreProfile, hasShopWxSession } from '../lib/api'; import { useStoreSession } from '../contexts/StoreSessionContext'; const PUBLIC_PATHS = new Set(['/login', '/legal/user-agreement', '/legal/privacy-policy']); const SELECT_STORE_PATH = '/select-store'; export default function AuthGate({ children }: { children: React.ReactNode }) { const { ready, authenticated, needsSelectStore } = useStoreSession(); const location = useLocation(); if (!ready) { return (

加载中…

); } if (authenticated && location.pathname === '/login') { return ; } if (authenticated && needsSelectStore && location.pathname !== SELECT_STORE_PATH) { return ; } if (!authenticated && !PUBLIC_PATHS.has(location.pathname)) { const profile = getStoreProfile(); if (profile && hasShopWxSession() && location.pathname !== '/login') { return ; } return ; } return <>{children}; }