14 lines
402 B
TypeScript
14 lines
402 B
TypeScript
|
|
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
|
||
|
|
}
|