diff --git a/apps/nextjs-app/src/lib/withAuthSSR.ts b/apps/nextjs-app/src/lib/withAuthSSR.ts
index d2485e0df..17c602cb7 100644
--- a/apps/nextjs-app/src/lib/withAuthSSR.ts
+++ b/apps/nextjs-app/src/lib/withAuthSSR.ts
@@ -1,6 +1,11 @@
import type { ParsedUrlQuery } from 'querystring';
import type { IHttpError } from '@teable/core';
-import type { GetServerSidePropsContext, GetServerSidePropsResult, PreviewData } from 'next';
+import type {
+ GetServerSidePropsContext,
+ GetServerSidePropsResult,
+ PreviewData,
+ GetServerSideProps as NextGetServerSideProps,
+} from 'next';
import { SsrApi } from '@/backend/api/rest/table.ssr';
export type GetServerSideProps<
@@ -16,7 +21,7 @@ export type GetServerSideProps<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function withAuthSSR
(
handler: GetServerSideProps
-) {
+): NextGetServerSideProps {
return async (context: GetServerSidePropsContext) => {
const req = context.req;
try {
@@ -42,6 +47,12 @@ export default function withAuthSSR
(
},
};
}
+ if (error.status == 404) {
+ return {
+ notFound: true,
+ };
+ }
+ console.error(error);
throw error;
}
};
diff --git a/apps/nextjs-app/src/pages/base/[baseId]/[tableId].tsx b/apps/nextjs-app/src/pages/base/[baseId]/[tableId].tsx
index 700b7f291..cbcaafa89 100644
--- a/apps/nextjs-app/src/pages/base/[baseId]/[tableId].tsx
+++ b/apps/nextjs-app/src/pages/base/[baseId]/[tableId].tsx
@@ -1,4 +1,3 @@
-import type { IHttpError } from '@teable/core';
import type { GetServerSideProps } from 'next';
import type { NextPageWithLayout } from '@/lib/type';
import withAuthSSR from '@/lib/withAuthSSR';
@@ -9,25 +8,14 @@ const Node: NextPageWithLayout = () => {
export const getServerSideProps: GetServerSideProps = withAuthSSR(async (context, ssrApi) => {
const { tableId, baseId, ...queryParams } = context.query;
- try {
- const queryString = new URLSearchParams(queryParams as Record).toString();
- const result = await ssrApi.getDefaultViewId(baseId as string, tableId as string);
- return {
- redirect: {
- destination: `/base/${baseId}/${tableId}/${result.id}?${queryString}`,
- permanent: false,
- },
- };
- } catch (e) {
- const error = e as IHttpError;
- if (error.status < 500) {
- return {
- notFound: true,
- };
- }
- console.error(error);
- throw error;
- }
+ const queryString = new URLSearchParams(queryParams as Record).toString();
+ const result = await ssrApi.getDefaultViewId(baseId as string, tableId as string);
+ return {
+ redirect: {
+ destination: `/base/${baseId}/${tableId}/${result.id}?${queryString}`,
+ permanent: false,
+ },
+ };
});
export default Node;
diff --git a/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/[viewId].tsx b/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/[viewId].tsx
index dba290d69..ba2a4e6f4 100644
--- a/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/[viewId].tsx
+++ b/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/[viewId].tsx
@@ -1,4 +1,3 @@
-import type { IHttpError } from '@teable/core';
import type { ReactElement } from 'react';
import type { ITableProps } from '@/features/app/blocks/table/Table';
import { Table } from '@/features/app/blocks/table/Table';
@@ -30,53 +29,42 @@ const Node: NextPageWithLayout = ({
export const getServerSideProps = withAuthSSR(async (context, ssrApi) => {
const { tableId, viewId, baseId, recordId, fromNotify: notifyId } = context.query;
- try {
- let recordServerData;
- if (recordId) {
- if (notifyId) {
- await ssrApi.updateNotificationStatus(notifyId as string, { isRead: true });
- }
+ let recordServerData;
+ if (recordId) {
+ if (notifyId) {
+ await ssrApi.updateNotificationStatus(notifyId as string, { isRead: true });
+ }
- recordServerData = await ssrApi.getRecord(tableId as string, recordId as string);
+ recordServerData = await ssrApi.getRecord(tableId as string, recordId as string);
- if (!recordServerData) {
- return {
- redirect: {
- destination: `/base/${baseId}/${tableId}/${viewId}`,
- permanent: false,
- },
- };
- }
- }
- const serverData = await getViewPageServerData(
- ssrApi,
- baseId as string,
- tableId as string,
- viewId as string
- );
- if (serverData) {
- const { i18nNamespaces } = tableConfig;
+ if (!recordServerData) {
return {
- props: {
- ...serverData,
- ...(recordServerData ? { recordServerData } : {}),
- ...(await getTranslationsProps(context, i18nNamespaces)),
+ redirect: {
+ destination: `/base/${baseId}/${tableId}/${viewId}`,
+ permanent: false,
},
};
}
+ }
+ const serverData = await getViewPageServerData(
+ ssrApi,
+ baseId as string,
+ tableId as string,
+ viewId as string
+ );
+ if (serverData) {
+ const { i18nNamespaces } = tableConfig;
return {
- notFound: true,
+ props: {
+ ...serverData,
+ ...(recordServerData ? { recordServerData } : {}),
+ ...(await getTranslationsProps(context, i18nNamespaces)),
+ },
};
- } catch (e) {
- const error = e as IHttpError;
- if (error.status < 500) {
- return {
- notFound: true,
- };
- }
- console.error(error);
- throw error;
}
+ return {
+ notFound: true,
+ };
});
Node.getLayout = function getLayout(page: ReactElement, pageProps: IViewPageProps) {
diff --git a/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/design.tsx b/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/design.tsx
index 0b6d01ded..8fa9b6a53 100644
--- a/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/design.tsx
+++ b/apps/nextjs-app/src/pages/base/[baseId]/[tableId]/design.tsx
@@ -1,4 +1,3 @@
-import type { IHttpError } from '@teable/core';
import type { ReactElement } from 'react';
import { Design } from '@/features/app/blocks/design/Design';
import { BaseLayout } from '@/features/app/layouts/BaseLayout';
@@ -16,30 +15,19 @@ const Node: NextPageWithLayout = (props) => {
export const getServerSideProps = withAuthSSR(async (context, ssrApi) => {
const { tableId, baseId } = context.query;
- try {
- const pageData = await getDesignPageServerData(ssrApi, baseId as string, tableId as string);
- if (pageData) {
- const { i18nNamespaces } = tableConfig;
- return {
- props: {
- ...pageData,
- ...(await getTranslationsProps(context, i18nNamespaces)),
- },
- };
- }
+ const pageData = await getDesignPageServerData(ssrApi, baseId as string, tableId as string);
+ if (pageData) {
+ const { i18nNamespaces } = tableConfig;
return {
- notFound: true,
+ props: {
+ ...pageData,
+ ...(await getTranslationsProps(context, i18nNamespaces)),
+ },
};
- } catch (e) {
- const error = e as IHttpError;
- if (error.status < 500) {
- return {
- notFound: true,
- };
- }
- console.error(error);
- throw error;
}
+ return {
+ notFound: true,
+ };
});
Node.getLayout = function getLayout(page: ReactElement, pageProps: IViewPageProps) {