Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
piccaSun committed Jun 13, 2024
1 parent 383a8bd commit cef8849
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-nails-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/portal-web": patch
---

修复门户系统桌面功能页面 token 过期不能跳转登录页面的问题
6 changes: 1 addition & 5 deletions apps/portal-web/src/pages/api/getClusterConfigFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export const getClusterConfigFilesSchema = typeboxRouteSchema({

200: Type.Object({
clusterConfigs: Type.Record(Type.String(), ClusterConfigSchema) }),

403: Type.Null(),
},
});

Expand All @@ -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<string, ClusterConfigSchema> = await getClusterConfigFiles();

return {
200: { clusterConfigs: modifiedClusters },
};
Expand Down
4 changes: 1 addition & 3 deletions apps/portal-web/src/pages/api/getClustersRuntimeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({
200: Type.Object({
results: Type.Array(ClusterRuntimeInfoSchema),
}),

403: Type.Null(),
},
});

Expand All @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions apps/portal-web/src/pages/desktop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<Props> = requireAuth(() => true)
((props: Props) => {

if ("error" in props) {
return <UnifiedErrorPage code={props.error} />;
}

const { enableLoginDesktop } = useStore(ClusterInfoStore);
if (!enableLoginDesktop || props.loginDesktopEnabledClusters.length === 0) {
return <NotFoundPage />;
Expand All @@ -54,6 +63,23 @@ export const getServerSideProps: GetServerSideProps<Props> = 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;
Expand Down

0 comments on commit cef8849

Please sign in to comment.