Procházet zdrojové kódy

validate globalNotificationId

kaori před 3 roky
rodič
revize
a0f8fe5df3

+ 12 - 2
packages/app/src/pages/admin/global-notification/[globalNotificationId].page.tsx

@@ -1,4 +1,6 @@
-import { isClient } from '@growi/core';
+import { useEffect } from 'react';
+
+import { isClient, objectIdUtils } from '@growi/core';
 import {
   NextPage, GetServerSideProps, GetServerSidePropsContext,
 } from 'next';
@@ -20,11 +22,19 @@ const AdminGlobalNotificationNewPage: NextPage<CommonProps> = (props) => {
   const { t } = useTranslation('admin');
   const router = useRouter();
   const { globalNotificationId } = router.query;
+  const currentGlobalNotificationId = Array.isArray(globalNotificationId) ? globalNotificationId[0] : globalNotificationId;
+
+
+  useEffect(() => {
+    if (globalNotificationId == null || (currentGlobalNotificationId != null && !objectIdUtils.isValidObjectId(currentGlobalNotificationId))) {
+      router.push('/admin/notification');
+    }
+  }, [currentGlobalNotificationId, globalNotificationId, router]);
+
 
   const title = t('external_notification.external_notification');
   const customTitle = useCustomTitle(props, title);
 
-  const currentGlobalNotificationId = Array.isArray(globalNotificationId) ? globalNotificationId[0] : globalNotificationId;
 
   const injectableContainers: Container<any>[] = [];