实现权限列表与权限渲染组件
This commit is contained in:
13
src/components/auth/index.ts
Normal file
13
src/components/auth/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useAtomValue } from "jotai"
|
||||
import type { ReactNode } from "react"
|
||||
import { scopesAtom } from "@/lib/stores/scopes"
|
||||
|
||||
export function Auth(props: { scope: string; children: ReactNode }) {
|
||||
const scopes = useAtomValue(scopesAtom)
|
||||
if (!scopes.length) return props.children
|
||||
|
||||
const hasScope = scopes.some(s => props.scope.startsWith(s))
|
||||
if (!hasScope) return null
|
||||
|
||||
return props.children
|
||||
}
|
||||
Reference in New Issue
Block a user