fix: in setting page display admin tab to only admin users
All checks were successful
Release to Staging / build_and_release (push) Successful in 45s
All checks were successful
Release to Staging / build_and_release (push) Successful in 45s
This commit is contained in:
parent
03f9269eb6
commit
822d5110a8
@ -14,6 +14,8 @@ import '../styles/settings.css'
|
|||||||
import '../styles/styles.css'
|
import '../styles/styles.css'
|
||||||
import '../styles/write.css'
|
import '../styles/write.css'
|
||||||
import { copyTextToClipboard } from '../utils'
|
import { copyTextToClipboard } from '../utils'
|
||||||
|
import { MetadataController } from '../controllers'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
export const SettingsPage = () => {
|
export const SettingsPage = () => {
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
@ -47,8 +49,21 @@ export const SettingsPage = () => {
|
|||||||
|
|
||||||
const SettingTabs = () => {
|
const SettingTabs = () => {
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
const [isAdmin, setIsAdmin] = useState(false)
|
||||||
const userState = useAppSelector((state) => state.user)
|
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 = () => {
|
const handleSignOut = () => {
|
||||||
logout()
|
logout()
|
||||||
}
|
}
|
||||||
@ -120,6 +135,7 @@ const SettingTabs = () => {
|
|||||||
</svg>
|
</svg>
|
||||||
Preference
|
Preference
|
||||||
</Link>
|
</Link>
|
||||||
|
{isAdmin && (
|
||||||
<Link
|
<Link
|
||||||
className={`btn btnMain btnMainAltText btnMainClear ${
|
className={`btn btnMain btnMainAltText btnMainClear ${
|
||||||
location.pathname === appRoutes.settingsAdmin
|
location.pathname === appRoutes.settingsAdmin
|
||||||
@ -140,6 +156,7 @@ const SettingTabs = () => {
|
|||||||
</svg>
|
</svg>
|
||||||
Admin
|
Admin
|
||||||
</Link>
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{userState.auth &&
|
{userState.auth &&
|
||||||
|
Loading…
Reference in New Issue
Block a user