Fix isAdmin check to be by role and not uid (#147)

* isAdmin should be based on role, not uid

* move admin link before sign in/out
This commit is contained in:
David Schultz 2023-05-20 14:35:33 -05:00 committed by GitHub
parent 0f58c44261
commit 5e4ecbb803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View file

@ -146,6 +146,17 @@ export function getButtons({
key="settings"
/>,
<ThemeButton key="theme-button" theme={theme} />,
isAdmin ? (
<FadeIn>
<NavButton
name="Admin"
key="admin"
icon={<Settings />}
value="admin"
href="/admin"
/>
</FadeIn>
) : undefined,
isAuthenticated === true ? (
<NavButton
name="Sign Out"
@ -171,17 +182,6 @@ export function getButtons({
href="/signin"
width={SIGN_IN_WIDTH}
/>
) : undefined,
isAdmin ? (
<FadeIn>
<NavButton
name="Admin"
key="admin"
icon={<Settings />}
value="admin"
href="/admin"
/>
</FadeIn>
) : undefined
].filter(Boolean)
}

View file

@ -24,7 +24,7 @@ export function useSessionSWR(swrOpts: SWRConfiguration = {}) {
isAuthenticated: session?.user?.id ? true : isLoading ? undefined : false,
/** undefined while loading */
isAdmin:
session?.user?.id === "admin" ? true : isLoading ? undefined : false,
session?.user?.role === "admin" ? true : isLoading ? undefined : false,
userId: session?.user?.id
}
}