You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

35 lines
728 B

import React from 'react'
import { Props } from './global'
import { useAtomValue } from 'jotai'
import { authAtom } from './store/system/user.ts'
export type AuthProps = Props & {
//是否渲染没有权限的组件
noAuth?: React.ReactNode
//权限key
authKey?: string[]
}
export const Auth: React.FC<AuthProps> = (props) => {
const auth = useAtomValue(authAtom)
if (!auth.isLogin) {
return null
}
if (props.authKey && props.authKey.length > 0) {
if (props.authKey.some(key => !auth.authKey?.includes(key))) {
return props.noAuth || null
}
}
return (
<>
{props!.children}
</>
)
}
export default Auth