feat: init new auth

This commit is contained in:
swve 2024-05-25 14:56:28 +02:00
parent f838a8512c
commit 1708b36818
34 changed files with 1853 additions and 3613 deletions

View file

@ -1,6 +1,6 @@
'use client'
import React from 'react'
import { useSession } from '@components/Contexts/SessionContext'
import { useSession } from 'next-auth/react'
import { useOrg } from '@components/Contexts/OrgContext'
interface AuthenticatedClientElementProps {
@ -8,11 +8,11 @@ interface AuthenticatedClientElementProps {
checkMethod: 'authentication' | 'roles'
orgId?: string
ressourceType?:
| 'collections'
| 'courses'
| 'activities'
| 'users'
| 'organizations'
| 'collections'
| 'courses'
| 'activities'
| 'users'
| 'organizations'
action?: 'create' | 'update' | 'delete' | 'read'
}
@ -49,19 +49,19 @@ export const AuthenticatedClientElement = (
}
function check() {
if (session.isAuthenticated === false) {
if (session.status == 'authenticated') {
setIsAllowed(false)
return
} else {
if (props.checkMethod === 'authentication') {
setIsAllowed(session.isAuthenticated)
} else if (props.checkMethod === 'roles') {
setIsAllowed(session.status == 'authenticated')
} else if (props.checkMethod === 'roles' && session.status == 'authenticated') {
return setIsAllowed(
isUserAllowed(
session.roles,
session?.data?.roles,
props.action!,
props.ressourceType!,
org.org_uuid
org?.org_uuid
)
)
}
@ -69,7 +69,7 @@ export const AuthenticatedClientElement = (
}
React.useEffect(() => {
if (session.isLoading) {
if (session.status == 'loading') {
return
}