diff --git a/apps/editor/src/app/App.tsx b/apps/editor/src/app/App.tsx index 4acdf8e..2107312 100644 --- a/apps/editor/src/app/App.tsx +++ b/apps/editor/src/app/App.tsx @@ -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(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) => { @@ -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 @@ -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 @@ -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) => { @@ -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. @@ -718,7 +727,7 @@ function AppInner() { [api, tenantId, activeFrameworkId], ) - if (authCallbackState === 'processing') { + if (authCallbackState === 'processing' || (authStatus === 'authenticated' && !membershipChecked)) { return (