diff --git a/.changeset/cyan-nails-brake.md b/.changeset/cyan-nails-brake.md new file mode 100644 index 0000000000..fbbc97b464 --- /dev/null +++ b/.changeset/cyan-nails-brake.md @@ -0,0 +1,5 @@ +--- +"@scow/portal-web": patch +--- + +修复门户系统桌面功能页面 token 过期不能跳转登录页面的问题 diff --git a/apps/portal-web/src/pages/api/getClusterConfigFiles.ts b/apps/portal-web/src/pages/api/getClusterConfigFiles.ts index 6ee048ab70..a3b9381fb1 100644 --- a/apps/portal-web/src/pages/api/getClusterConfigFiles.ts +++ b/apps/portal-web/src/pages/api/getClusterConfigFiles.ts @@ -44,8 +44,6 @@ export const getClusterConfigFilesSchema = typeboxRouteSchema({ 200: Type.Object({ clusterConfigs: Type.Record(Type.String(), ClusterConfigSchema) }), - - 403: Type.Null(), }, }); @@ -59,11 +57,9 @@ export default route(getClusterConfigFilesSchema, // 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 { 403: null }; } + if (!info) { return; } const modifiedClusters: Record = await getClusterConfigFiles(); - return { 200: { clusterConfigs: modifiedClusters }, }; diff --git a/apps/portal-web/src/pages/api/getClustersRuntimeInfo.ts b/apps/portal-web/src/pages/api/getClustersRuntimeInfo.ts index 72da263b04..e19d996138 100644 --- a/apps/portal-web/src/pages/api/getClustersRuntimeInfo.ts +++ b/apps/portal-web/src/pages/api/getClustersRuntimeInfo.ts @@ -32,8 +32,6 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({ 200: Type.Object({ results: Type.Array(ClusterRuntimeInfoSchema), }), - - 403: Type.Null(), }, }); @@ -44,7 +42,7 @@ export default route(GetClustersRuntimeInfoSchema, // 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 { 403: null }; } + if (!info) { return; } const reply = await libGetClustersRuntimeInfo(publicConfig.MIS_SERVER_URL, runtimeConfig.SCOW_API_AUTH_TOKEN); return { diff --git a/apps/portal-web/src/pages/desktop/index.tsx b/apps/portal-web/src/pages/desktop/index.tsx index 4b068d1753..4102e38d8f 100644 --- a/apps/portal-web/src/pages/desktop/index.tsx +++ b/apps/portal-web/src/pages/desktop/index.tsx @@ -16,9 +16,12 @@ import { getCurrentLanguageId, getI18nConfigCurrentText } from "@scow/lib-web/bu import { GetServerSideProps, NextPage } from "next"; import { useStore } from "simstate"; import { api } from "src/apis"; +import { USE_MOCK } from "src/apis/useMock"; import { getTokenFromCookie } from "src/auth/cookie"; import { requireAuth } from "src/auth/requireAuth"; +import { AuthResultError, ssrAuthenticate } from "src/auth/server"; import { NotFoundPage } from "src/components/errorPages/NotFoundPage"; +import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage"; import { PageTitle } from "src/components/PageTitle"; import { useI18nTranslateToString } from "src/i18n"; import { DesktopTable } from "src/pageComponents/desktop/DesktopTable"; @@ -27,12 +30,18 @@ import { Cluster, getLoginDesktopEnabled } from "src/utils/cluster"; import { publicConfig } from "src/utils/config"; import { Head } from "src/utils/head"; type Props = { + error: AuthResultError; +} | { loginDesktopEnabledClusters: Cluster[]; }; export const DesktopIndexPage: NextPage = requireAuth(() => true) ((props: Props) => { + if ("error" in props) { + return ; + } + const { enableLoginDesktop } = useStore(ClusterInfoStore); if (!enableLoginDesktop || props.loginDesktopEnabledClusters.length === 0) { return ; @@ -54,6 +63,23 @@ export const getServerSideProps: GetServerSideProps = async ({ req }) => const languageId = getCurrentLanguageId(req, publicConfig.SYSTEM_LANGUAGE_CONFIG); + // Cannot directly call api routes here, so mock is not available directly. + // manually call mock + if (USE_MOCK) { + return { + props: { + loginDesktopEnabledClusters: [ { id: "hpc01", name: "hpc01Name" } ], + }, + }; + } + + const auth = ssrAuthenticate(() => true); + + const info = await auth(req); + if (typeof info === "number") { + return { props: { error: info } }; + } + const token = getTokenFromCookie({ req }); const resp = await api.getClusterConfigFiles({ query: { token } }); const clusterConfigs = resp.clusterConfigs;