fix super user check
This commit is contained in:
parent
8b92a780bf
commit
80f9b43022
2 changed files with 5 additions and 2 deletions
|
@ -7,9 +7,11 @@ import { setGlobal } from '../femtoApp.ts'
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string
|
id: string
|
||||||
username: string
|
username: string
|
||||||
roles: string[]
|
roles: Role[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Role = 'User' | 'SuperUser'
|
||||||
|
|
||||||
let globalUser: User | null
|
let globalUser: User | null
|
||||||
|
|
||||||
export function initUser() {
|
export function initUser() {
|
||||||
|
|
|
@ -6,10 +6,11 @@ type NavBarProps = unknown
|
||||||
|
|
||||||
export default function NavBar({ children }: PropsWithChildren<NavBarProps>) {
|
export default function NavBar({ children }: PropsWithChildren<NavBarProps>) {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
const isSuperUser = user?.roles.includes('SuperUser')
|
||||||
return (
|
return (
|
||||||
<nav className={`w-full flex flex-row justify-end gap-4 px-4 md:px-8 py-3`}>
|
<nav className={`w-full flex flex-row justify-end gap-4 px-4 md:px-8 py-3`}>
|
||||||
{children}
|
{children}
|
||||||
{user?.isSuperUser && <NavButton to={'/admin/codes'}>admin</NavButton>}
|
{isSuperUser && <NavButton to={'/admin/codes'}>admin</NavButton>}
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue