Catalyst / admin/Synapse-Cortex 14.8 GB / 57.8 GB 40.0 GB free
Help Sign in

admin / Synapse-Cortex

public

Self Hosted ITSM Tool with RBAC/Tenanting and MFA

Code Issues Pull requests Pipelines Packages Security Insights Wiki Settings
Synapse-Cortex / Synapse-Cortexv2 / frontend / src / auth / SetupGate.tsx 847 B · main
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { useEffect, useState, type ReactNode } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { setupApi } from '../api/setup'

export function SetupGate({ children }: { children: ReactNode }) {
  const [needsSetup, setNeedsSetup] = useState<boolean | null>(null)
  const location = useLocation()
  const navigate = useNavigate()

  useEffect(() => {
    setupApi.status().then((res) => setNeedsSetup(res.needs_setup))
  }, [])

  useEffect(() => {
    if (needsSetup === null) return
    if (needsSetup && location.pathname !== '/setup') {
      navigate('/setup', { replace: true })
    } else if (!needsSetup && location.pathname === '/setup') {
      navigate('/login', { replace: true })
    }
  }, [needsSetup, location.pathname, navigate])

  if (needsSetup === null) return null
  return <>{children}</>
}