From 822d5110a893d2e606c3383770886e4993c3bb35 Mon Sep 17 00:00:00 2001 From: daniyal Date: Tue, 3 Sep 2024 16:47:47 +0500 Subject: [PATCH] fix: in setting page display admin tab to only admin users --- src/pages/settings.tsx | 55 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/pages/settings.tsx b/src/pages/settings.tsx index a86a6eb..3783d3f 100644 --- a/src/pages/settings.tsx +++ b/src/pages/settings.tsx @@ -14,6 +14,8 @@ import '../styles/settings.css' import '../styles/styles.css' import '../styles/write.css' import { copyTextToClipboard } from '../utils' +import { MetadataController } from '../controllers' +import { useEffect, useState } from 'react' export const SettingsPage = () => { const location = useLocation() @@ -47,8 +49,21 @@ export const SettingsPage = () => { const SettingTabs = () => { const location = useLocation() + const [isAdmin, setIsAdmin] = useState(false) const userState = useAppSelector((state) => state.user) + useEffect(() => { + MetadataController.getInstance().then((controller) => { + if (userState.auth && userState.user?.npub) { + setIsAdmin( + controller.adminNpubs.includes(userState.user.npub as string) + ) + } else { + setIsAdmin(false) + } + }) + }, [userState]) + const handleSignOut = () => { logout() } @@ -120,26 +135,28 @@ const SettingTabs = () => { Preference - - - - - Admin - + + + + Admin + + )} {userState.auth &&