mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init new auth
This commit is contained in:
parent
f838a8512c
commit
1708b36818
34 changed files with 1853 additions and 3613 deletions
|
|
@ -1,24 +1,27 @@
|
|||
import { useOrg } from '@components/Contexts/OrgContext'
|
||||
import { useSession } from '@components/Contexts/SessionContext'
|
||||
import { useSession } from 'next-auth/react'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
function useAdminStatus() {
|
||||
const session = useSession() as any
|
||||
const org = useOrg() as any
|
||||
console.log('useAdminStatus', {
|
||||
session,
|
||||
})
|
||||
|
||||
// If session is not loaded, redirect to login
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (session.isLoading) {
|
||||
if (session.status == 'loading') {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
, [session])
|
||||
, [session])
|
||||
|
||||
const isUserAdmin = () => {
|
||||
if (session.isAuthenticated) {
|
||||
const isAdmin = session.roles.some((role: any) => {
|
||||
if (session.status == 'authenticated') {
|
||||
const isAdmin = session?.data?.roles.some((role: any) => {
|
||||
return (
|
||||
role.org.id === org.id &&
|
||||
(role.role.id === 1 ||
|
||||
|
|
@ -31,7 +34,7 @@ function useAdminStatus() {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
// Return the user admin status
|
||||
return isUserAdmin()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue