diff --git a/apps/mis-web/src/pages/_app.tsx b/apps/mis-web/src/pages/_app.tsx index 63cebfaf15..14688db570 100644 --- a/apps/mis-web/src/pages/_app.tsx +++ b/apps/mis-web/src/pages/_app.tsx @@ -262,14 +262,14 @@ MyApp.getInitialProps = async (appContext: AppContext) => { const simpleClustersInfo = await api.getSimpleClustersInfoFromConfigFiles({}).then((x) => x, () => ({ clustersInfo: {} })); - extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo; + extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo ?? {}; const publicConfigClusters = extra.clusterConfigs && Object.keys(extra.clusterConfigs).length > 0 ? getPublicConfigClusters(extra.clusterConfigs) : getPublicConfigClusters(extra.initialSimpleClustersInfo) ?? {}; const activatedClusters = formatActivatedClusters({ - clustersRuntimeInfo: clustersRuntimeInfo?.results, + clustersRuntimeInfo: clustersRuntimeInfo?.results ?? [], misConfigClusters: publicConfigClusters }); extra.initialActivatedClusters = activatedClusters.misActivatedClusters ?? {}; diff --git a/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts b/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts index 91a4f3781b..0d20135c3d 100644 --- a/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts +++ b/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts @@ -36,6 +36,8 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({ 200: Type.Object({ results: Type.Array(ClusterRuntimeInfoSchema), }), + + 403: Type.Null(), }, }); @@ -46,11 +48,12 @@ export default route(GetClustersRuntimeInfoSchema, // if not initialized, every one can get clustersRuntimeInfo if (await queryIfInitialized()) { + const { token } = req.query; // when firstly used in getInitialProps, check the token // when logged in, use auth() const info = token ? await validateToken(token) : await auth(req, res); - if (!info) { return; } + if (!info) { return { 403: null }; } } const client = getClient(ConfigServiceClient); diff --git a/apps/mis-web/src/pages/api/simpleClustersInfo.ts b/apps/mis-web/src/pages/api/simpleClustersInfo.ts index 1df3ad4023..799ed36384 100644 --- a/apps/mis-web/src/pages/api/simpleClustersInfo.ts +++ b/apps/mis-web/src/pages/api/simpleClustersInfo.ts @@ -37,6 +37,8 @@ export const GetSimpleClustersInfoFromConfigFilesSchema = typeboxRouteSchema({ 200: Type.Object({ clustersInfo: Type.Record(Type.String(), SimpleClusterSchema) }), + + 403: Type.Null(), }, }); @@ -47,7 +49,7 @@ export default route(GetSimpleClustersInfoFromConfigFilesSchema, // if not initialized, every one can getSimpleClusterInfo which includes clusterId, displayedName and priority if (await queryIfInitialized()) { const info = await auth(req, res); - if (!info) { return; } + if (!info) { return { 403: null }; } } const clustersFullInfo: Record = await getClusterConfigFiles();