Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions apps/editor/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,29 @@ function AppInner() {
}, [authStatus, route])

// First login: give the user the default role (idempotent) and refresh their token if it did.
// Server data waits for this, so the first requests carry the new role.
const ensureSelfAttempted = useRef<string | null>(null)
const [membershipChecked, setMembershipChecked] = useState(false)
const appReady = authStatus === 'authenticated' && membershipChecked
useEffect(() => {
if (authStatus !== 'authenticated' || !tenantId) return
if (authStatus !== 'authenticated') return
if (!tenantId) {
setMembershipChecked(true)
return
}
const key = tenantId
if (ensureSelfAttempted.current === key) return
ensureSelfAttempted.current = key
ensureDefaultMembership(api, tenantId, refreshAccessToken).catch((err: unknown) => {
console.warn('[App] ensure-self failed:', err)
})
ensureDefaultMembership(api, tenantId, refreshAccessToken)
.catch((err: unknown) => {
console.warn('[App] ensure-self failed:', err)
})
.finally(() => setMembershipChecked(true))
}, [authStatus, tenantId, api, refreshAccessToken])

// Fetch the full definitions catalogue from the management endpoint once authenticated.
useEffect(() => {
if (authStatus !== 'authenticated' || !tenantId) return
if (!appReady || !tenantId) return
let cancelled = false
console.log('[App] Fetching definitions catalogue for tenant:', tenantId)
api.listDefinitions({ tenantId }).then((defs) => {
Expand Down Expand Up @@ -234,11 +243,11 @@ function AppInner() {
console.warn('[App] Failed to load definitions catalogue:', err)
})
return () => { cancelled = true }
}, [authStatus, tenantId, api])
}, [appReady, tenantId, api])

// Fetch server framework list so tree-view crosswalk selector can show all tenant frameworks.
useEffect(() => {
if (authStatus !== 'authenticated') return
if (!appReady) return
let cancelled = false
api.listCfDocuments({ caseVersion: 'v1p1', includeArchived: false }).then((docs) => {
if (cancelled) return
Expand All @@ -247,7 +256,7 @@ function AppInner() {
console.warn('[App] Failed to load server framework list:', err)
})
return () => { cancelled = true }
}, [authStatus, api])
}, [appReady, api])

const activeFramework = useMemo(() => {
if (!activeFrameworkId) return null
Expand Down Expand Up @@ -421,7 +430,7 @@ function AppInner() {
// Falls back to home if it can't be loaded (deleted, no access, etc.).
useEffect(() => {
if (!activeFrameworkId) return
if (authStatus !== 'authenticated') return
if (!appReady) return
if (serverVerifiedIds.has(activeFrameworkId)) return
let cancelled = false
openRemoteFramework(activeFrameworkId, { replace: true }).catch((err: unknown) => {
Expand All @@ -430,7 +439,7 @@ function AppInner() {
navigateHome({ replace: true })
})
return () => { cancelled = true }
}, [activeFrameworkId, authStatus, serverVerifiedIds, openRemoteFramework, navigateHome])
}, [activeFrameworkId, appReady, serverVerifiedIds, openRemoteFramework, navigateHome])

// Load a framework from the server into the local session without navigating to it.
// Used by TreePanelView when the user selects a crosswalk target that isn't loaded locally yet.
Expand Down Expand Up @@ -718,7 +727,7 @@ function AppInner() {
[api, tenantId, activeFrameworkId],
)

if (authCallbackState === 'processing') {
if (authCallbackState === 'processing' || (authStatus === 'authenticated' && !membershipChecked)) {
return (
<div className="min-h-screen w-full bg-slate-50">
<div className="mx-auto w-full max-w-2xl px-5 py-12">
Expand Down
Loading