import { useEffect } from "react" import { useLayoutStore } from "./store" import { useShallow } from "zustand/shallow" import { LogIn, LockKeyhole } from "lucide-react" type Props = { children?: React.ReactNode, mustLogin?: boolean, } export const AuthProvider = ({ children, mustLogin }: Props) => { const store = useLayoutStore(useShallow(state => ({ init: state.init, me: state.me, }))); useEffect(() => { store.init() }, []) const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href); if (mustLogin && !store.me) { return (

需要登录

请先登录以继续访问此页面

{ window.open(loginUrl, '_self') }} > 立即登录
) } return <> {children} }