Files
dukang/apps/h5-partner/src/components/AuthGate.tsx
T
jacy 83ed90ef67
CI / verify (pull_request) Has been cancelled
feat(h5-auth): remember SMS sessions and simplify media access
Hide WeChat login for shop and partner users, keep verified sessions for seven days, and allow JSSDK camera or album access without an OpenID binding.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-21 10:41:17 +08:00

26 lines
899 B
TypeScript

import { Navigate, useLocation } from 'react-router-dom';
import { getPartnerProfile } 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 <div className="empty">加载中...</div>;
}
if (authenticated && location.pathname === '/login') {
return <Navigate to={partnerHomePath(account ?? getPartnerProfile())} replace />;
}
if (!authenticated && !PUBLIC_PATHS.has(location.pathname)) {
return <Navigate to="/login" replace state={{ from: location }} />;
}
return <>{children}</>;
}