fix: Header Role Indicator + Disable course creation wording if user isn't connected

This commit is contained in:
swve 2024-03-19 22:34:28 +01:00
parent a124cde229
commit 7398e9e946
9 changed files with 85 additions and 169 deletions

View file

@ -0,0 +1,40 @@
import { useOrg } from '@components/Contexts/OrgContext'
import { useSession } from '@components/Contexts/SessionContext'
import { useEffect } from 'react'
function useAdminStatus() {
const session = useSession() as any
const org = useOrg() as any
// If session is not loaded, redirect to login
useEffect(() => {
if (session.isLoading) {
return
}
}
, [session])
const isUserAdmin = () => {
if (session.isAuthenticated) {
const isAdmin = session.roles.some((role: any) => {
return (
role.org.id === org.id &&
(role.role.id === 1 ||
role.role.id === 2 ||
role.role.role_uuid === 'role_global_admin' ||
role.role.role_uuid === 'role_global_maintainer')
)
})
return isAdmin
}
return false
}
// Return the user admin status
return isUserAdmin()
}
export default useAdminStatus