Просмотр исходного кода

Clean URL by removing query parameters after rendering

maeshinshin 1 год назад
Родитель
Сommit
22d79223f3
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      apps/app/src/pages/login/index.page.tsx

+ 10 - 1
apps/app/src/pages/login/index.page.tsx

@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
 
 
 import { IExternalAuthProviderType } from '@growi/core';
 import { IExternalAuthProviderType } from '@growi/core';
 import type {
 import type {
@@ -7,6 +7,7 @@ import type {
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
 import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
 import Head from 'next/head';
 import Head from 'next/head';
+import { useRouter } from 'next/router';
 
 
 import { NoLoginLayout } from '~/components/Layout/NoLoginLayout';
 import { NoLoginLayout } from '~/components/Layout/NoLoginLayout';
 import { LoginForm } from '~/components/LoginForm';
 import { LoginForm } from '~/components/LoginForm';
@@ -43,6 +44,14 @@ type Props = CommonProps & {
 const LoginPage: NextPage<Props> = (props: Props) => {
 const LoginPage: NextPage<Props> = (props: Props) => {
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
+  const router = useRouter();
+  useEffect(() => {
+    if (router.query.externalAccountLoginError) {
+      const cleanUrl = router.pathname;
+      router.replace(cleanUrl, undefined, { shallow: true });
+    }
+  }, [router]);
+
   // commons
   // commons
   useCsrfToken(props.csrfToken);
   useCsrfToken(props.csrfToken);