From 02a622019542ddde3f6d9edf4e1c4aa90197658e Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 30 Nov 2026 21:03:19 +0000 Subject: [PATCH] Load server data only after the first-login role grant (CGE-192) On a first login, the home screen loaded CFPackages while ensure-self was still giving the user Author, with the token from before. The request got 403 until a reload. The app now waits for ensure-self and its token refresh before it loads definitions, the framework list, or a framework from the URL, and before it shows a screen. --- apps/editor/src/app/App.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/editor/src/app/App.tsx b/apps/editor/src/app/App.tsx index 4acdf8e..b4aa054 100644 --- a/apps/editor/src/app/App.tsx +++ b/apps/editor/src/app/App.tsx @@ -190,7 +190,10 @@ function AppInner() { }, [authStatus, route]) // First login: give the user the default role (idempotent) and refresh their token if it did. + // Nothing loads server data until this is done: a request with the token from before the + // role was given gets 403. const ensureSelfAttempted = useRef(null) + const [ensureSelfDone, setEnsureSelfDone] = useState(null) useEffect(() => { if (authStatus !== 'authenticated' || !tenantId) return const key = tenantId @@ -198,12 +201,13 @@ function AppInner() { ensureSelfAttempted.current = key ensureDefaultMembership(api, tenantId, refreshAccessToken).catch((err: unknown) => { console.warn('[App] ensure-self failed:', err) - }) + }).finally(() => setEnsureSelfDone(key)) }, [authStatus, tenantId, api, refreshAccessToken]) + const ready = authStatus === 'authenticated' && (!tenantId || ensureSelfDone === tenantId) // Fetch the full definitions catalogue from the management endpoint once authenticated. useEffect(() => { - if (authStatus !== 'authenticated' || !tenantId) return + if (!ready || !tenantId) return let cancelled = false console.log('[App] Fetching definitions catalogue for tenant:', tenantId) api.listDefinitions({ tenantId }).then((defs) => { @@ -234,11 +238,11 @@ function AppInner() { console.warn('[App] Failed to load definitions catalogue:', err) }) return () => { cancelled = true } - }, [authStatus, tenantId, api]) + }, [ready, tenantId, api]) // Fetch server framework list so tree-view crosswalk selector can show all tenant frameworks. useEffect(() => { - if (authStatus !== 'authenticated') return + if (!ready) return let cancelled = false api.listCfDocuments({ caseVersion: 'v1p1', includeArchived: false }).then((docs) => { if (cancelled) return @@ -247,7 +251,7 @@ function AppInner() { console.warn('[App] Failed to load server framework list:', err) }) return () => { cancelled = true } - }, [authStatus, api]) + }, [ready, api]) const activeFramework = useMemo(() => { if (!activeFrameworkId) return null @@ -421,7 +425,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 (!ready) return if (serverVerifiedIds.has(activeFrameworkId)) return let cancelled = false openRemoteFramework(activeFrameworkId, { replace: true }).catch((err: unknown) => { @@ -430,7 +434,7 @@ function AppInner() { navigateHome({ replace: true }) }) return () => { cancelled = true } - }, [activeFrameworkId, authStatus, serverVerifiedIds, openRemoteFramework, navigateHome]) + }, [activeFrameworkId, ready, 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. @@ -749,6 +753,11 @@ function AppInner() { return } + if (!ready) { + // First login: the default role and its new token, before any screen loads server data. + return null + } + const homeScreen = (