mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: Header Role Indicator + Disable course creation wording if user isn't connected
This commit is contained in:
parent
a124cde229
commit
7398e9e946
9 changed files with 85 additions and 169 deletions
40
apps/web/components/Hooks/useAdminStatus.tsx
Normal file
40
apps/web/components/Hooks/useAdminStatus.tsx
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue