You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GHHub/src/components/RequireAuth.jsx

22 lines
677 B
React

import { Result } from 'antd'
import { usingStorage } from '@/hooks/usingStorage'
import useAuthStore from '@/stores/Auth'
export default function RequireAuth({ children, ...props }) {
const [isPermitted, currentUser] = useAuthStore(state => [state.isPermitted, state.currentUser])
const { userId } = usingStorage()
if (isPermitted(props.subject)) {
// if (props.subject === '/account/management1') {
return children
} else if (props.result) {
return (
<Result
status='403'
title='403'
subTitle={`抱歉,你(${currentUser.username})没有权限使用该功能(${props.subject})。`}
/>
)
}
}