mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Merge pull request #166 from learnhouse/swve/eng-151-make-sure-org-is-not-accessible-if-orgconfig-says-so
Add Organization active status verification
This commit is contained in:
commit
700d84bd5e
1 changed files with 12 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import { swrFetcher } from '@services/utils/ts/requests'
|
||||||
import React, { useContext, useEffect } from 'react'
|
import React, { useContext, useEffect } from 'react'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { createContext } from 'react'
|
import { createContext } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
export const OrgContext = createContext({}) as any
|
export const OrgContext = createContext({}) as any
|
||||||
|
|
||||||
|
|
@ -15,7 +16,17 @@ export function OrgProvider({
|
||||||
orgslug: string
|
orgslug: string
|
||||||
}) {
|
}) {
|
||||||
const { data: org } = useSWR(`${getAPIUrl()}orgs/slug/${orgslug}`, swrFetcher)
|
const { data: org } = useSWR(`${getAPIUrl()}orgs/slug/${orgslug}`, swrFetcher)
|
||||||
useEffect(() => {}, [org])
|
const router = useRouter()
|
||||||
|
// Check if Org is Active
|
||||||
|
const verifyIfOrgIsActive = () => {
|
||||||
|
if (org && org?.config.config.GeneralConfig.active === false) {
|
||||||
|
router.push('/404')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
verifyIfOrgIsActive()
|
||||||
|
}, [org])
|
||||||
|
|
||||||
return <OrgContext.Provider value={org}>{children}</OrgContext.Provider>
|
return <OrgContext.Provider value={org}>{children}</OrgContext.Provider>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue