From 3e64f46d92754d8fc3c30c8dac5a18674c8fa72c Mon Sep 17 00:00:00 2001 From: papapatrick <109422393+Patrickill@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:19:48 +0800 Subject: [PATCH] fix: change ip detect url (#2827) --- projects/app/src/pages/login/index.tsx | 46 +++++++++++--------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/projects/app/src/pages/login/index.tsx b/projects/app/src/pages/login/index.tsx index a2ad06ee2..6c27d44d0 100644 --- a/projects/app/src/pages/login/index.tsx +++ b/projects/app/src/pages/login/index.tsx @@ -26,12 +26,15 @@ import { useLocalStorageState, useMount } from 'ahooks'; import { useTranslation } from 'next-i18next'; import I18nLngSelector from '@/components/Select/I18nLngSelector'; import { useSystem } from '@fastgpt/web/hooks/useSystem'; +import { GET } from '@/web/common/api/request'; const RegisterForm = dynamic(() => import('./components/RegisterForm')); const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm')); const WechatForm = dynamic(() => import('./components/LoginForm/WechatForm')); const CommunityModal = dynamic(() => import('@/components/CommunityModal')); +const ipDetectURL = 'https://qifu-api.baidubce.com/ip/local/geo/v1/district'; + const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => { const router = useRouter(); const { t } = useTranslation(); @@ -48,6 +51,21 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => { onClose: onCloseRedirect } = useDisclosure(); + const [showRedirect, setShowRedirect] = useLocalStorageState('showRedirect', { + defaultValue: true + }); + + const checkIpInChina = useCallback( + () => + GET(ipDetectURL).then((res: any) => { + const country = res?.country; + if (country && country === '中国' && res.city !== '中国香港') { + onOpenRedirect(); + } + }), + [onOpenRedirect] + ); + const loginSuccess = useCallback( (res: ResLogin) => { // init store @@ -85,27 +103,10 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => { useMount(() => { clearToken(); + ChineseRedirectUrl && showRedirect && checkIpInChina(); router.prefetch('/app/list'); }); - const [showRedirect, setShowRedirect] = useLocalStorageState('chinese_ip_redirect', { - defaultValue: true - }); - const checkIpInChina = useCallback(() => { - const onSuccess = (res: any) => { - if (!res.country.iso_code) { - return; - } - - const country = res.country.iso_code.toLowerCase(); - if (country === 'cn') { - onOpenRedirect(); - } - }; - const onError = (e: any) => console.log(e); - geoip2 && geoip2.country(onSuccess, onError); - }, [onOpenRedirect]); - return ( <> {feConfigs.googleClientVerKey && ( @@ -114,14 +115,6 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => { > )} - {ChineseRedirectUrl && showRedirect && ( - - )} - { {isOpen && } + {showRedirect && (