From 5e4ecbb8034f28f393c93d1d1d52114f1975ae4a Mon Sep 17 00:00:00 2001 From: David Schultz Date: Sat, 20 May 2023 14:35:33 -0500 Subject: [PATCH] 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 --- src/app/components/header/buttons.tsx | 22 +++++++++++----------- src/lib/use-session-swr.ts | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/components/header/buttons.tsx b/src/app/components/header/buttons.tsx index c064afd3..66e0efb9 100644 --- a/src/app/components/header/buttons.tsx +++ b/src/app/components/header/buttons.tsx @@ -146,6 +146,17 @@ export function getButtons({ key="settings" />, , + isAdmin ? ( + + } + value="admin" + href="/admin" + /> + + ) : undefined, isAuthenticated === true ? ( - ) : undefined, - isAdmin ? ( - - } - value="admin" - href="/admin" - /> - ) : undefined ].filter(Boolean) } diff --git a/src/lib/use-session-swr.ts b/src/lib/use-session-swr.ts index f86cab77..27da0c24 100644 --- a/src/lib/use-session-swr.ts +++ b/src/lib/use-session-swr.ts @@ -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 } }