实现权限列表与权限渲染组件

This commit is contained in:
2026-03-31 10:56:01 +08:00
parent 2c7970796f
commit 12b60e74df
7 changed files with 94 additions and 3 deletions

View 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
}