import { useEffect } from "react" import { useLayoutStore } from "./store" import { useShallow } from "zustand/shallow" import { LogIn, LockKeyhole } from "lucide-react" export { BaseHeader } from './modules/BaseHeader' import { useMemo } from 'react'; import { useLocation, useNavigate } from '@tanstack/react-router'; type Props = { children?: React.ReactNode, mustLogin?: boolean, } export const AuthProvider = ({ children, mustLogin }: Props) => { const store = useLayoutStore(useShallow(state => ({ init: state.init, me: state.me, openLinkList: state.openLinkList, }))); useEffect(() => { store.init() }, []) const location = useLocation() const navigate = useNavigate(); const isOpen = useMemo(() => { return store.openLinkList.some(item => location.pathname.startsWith(item)) }, [location.pathname]) const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href); if (mustLogin && !store.me && !isOpen) { return (
请先登录以继续访问此页面