diff --git a/frontend/desktop/src/api/platform.ts b/frontend/desktop/src/api/platform.ts index 11e1b3ba0387..34ae061e6b4f 100644 --- a/frontend/desktop/src/api/platform.ts +++ b/frontend/desktop/src/api/platform.ts @@ -5,17 +5,17 @@ import { CloudConfigType, AuthClientConfigType, AppClientConfigType, - CommonConfigType, CommonClientConfigType, TNotification } from '@/types'; import { AccountCRD } from '@/types/user'; +import { getBaiduId } from '@/utils/sessionConfig'; // handle baidu export const uploadConvertData = (newType: number[], url?: string) => { const defaultUrl = 'https://sealos.run/self-hosting'; const main_url = url || defaultUrl; - const bd_vid = localStorage.getItem('bd_vid'); + const bd_vid = getBaiduId(); if (!bd_vid) { return Promise.reject('upload convert data params error'); } diff --git a/frontend/desktop/src/components/signin/index.tsx b/frontend/desktop/src/components/signin/index.tsx index 5541946d2810..e5c782e050cb 100644 --- a/frontend/desktop/src/components/signin/index.tsx +++ b/frontend/desktop/src/components/signin/index.tsx @@ -27,9 +27,11 @@ import { useRouter } from 'next/router'; import { useEffect, useMemo, useRef, useState } from 'react'; import useWechat from './auth/useWechat'; import { Turnstile, TurnstileInstance } from '@marsidev/react-turnstile'; +import { getBaiduId } from '@/utils/sessionConfig'; export default function SigninComponent() { const conf = useConfigStore(); + const hasBaiduToken = conf.authConfig?.hasBaiduToken; const needPassword = conf.authConfig?.idp.password?.enabled; const needSms = conf.authConfig?.idp.sms?.enabled; const needTabs = conf.authConfig?.idp.password?.enabled && conf.authConfig?.idp.sms?.enabled; @@ -247,7 +249,7 @@ export default function SigninComponent() { ? (t('common:loading') || 'Loading') + '...' : t('common:log_in') || 'Log In'} - + {hasBaiduToken && getBaiduId() ? : } )} diff --git a/frontend/desktop/src/pages/api/platform/getAuthConfig.ts b/frontend/desktop/src/pages/api/platform/getAuthConfig.ts index be538cfa7c87..3b90c3f61fee 100644 --- a/frontend/desktop/src/pages/api/platform/getAuthConfig.ts +++ b/frontend/desktop/src/pages/api/platform/getAuthConfig.ts @@ -53,7 +53,7 @@ function genResAuthClientConfig(conf: AuthConfigType) { } }, proxyAddress: conf.proxyAddress || '', - baiduToken: conf.baiduToken || '' + hasBaiduToken: !!conf.baiduToken }; return authClientConfig; } diff --git a/frontend/desktop/src/pages/index.tsx b/frontend/desktop/src/pages/index.tsx index 6d65f03c9c76..81e3fe75a582 100644 --- a/frontend/desktop/src/pages/index.tsx +++ b/frontend/desktop/src/pages/index.tsx @@ -3,7 +3,7 @@ import useAppStore from '@/stores/app'; import { useConfigStore } from '@/stores/config'; import useSessionStore from '@/stores/session'; import { parseOpenappQuery } from '@/utils/format'; -import { setInviterId, setUserSemChannel } from '@/utils/sessionConfig'; +import { setBaiduId, setInviterId, setUserSemChannel } from '@/utils/sessionConfig'; import { compareFirstLanguages } from '@/utils/tools'; import { Box, useColorMode } from '@chakra-ui/react'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; @@ -86,7 +86,7 @@ export default function Home({ sealos_cloud_domain }: { sealos_cloud_domain: str useEffect(() => { const { bd_vid, s } = router.query; if (bd_vid) { - localStorage.setItem('bd_vid', bd_vid as string); + setBaiduId(bd_vid as string); } // handle new user sem source diff --git a/frontend/desktop/src/types/system.ts b/frontend/desktop/src/types/system.ts index 26faf54e024d..3259e73584ee 100644 --- a/frontend/desktop/src/types/system.ts +++ b/frontend/desktop/src/types/system.ts @@ -74,6 +74,7 @@ export type AuthConfigType = { callbackURL: string; signUpEnabled?: boolean; baiduToken?: string; + hasBaiduToken?: boolean; jwt: JwtConfigType; billingUrl?: string; workorderUrl?: string; @@ -137,6 +138,7 @@ export type AuthClientConfigType = DeepRequired< OmitPathArr< AuthConfigType, [ + 'baiduToken', 'signUpEnabled', 'invite.lafSecretKey', 'invite.lafBaseURL', @@ -225,7 +227,7 @@ export const DefaultLayoutConfig: LayoutConfigType = { }; export const DefaultAuthClientConfig: AuthClientConfigType = { - baiduToken: '', + hasBaiduToken: false, invite: { enabled: false }, diff --git a/frontend/desktop/src/utils/sessionConfig.ts b/frontend/desktop/src/utils/sessionConfig.ts index 1b98b6783564..a0324ea60c1e 100644 --- a/frontend/desktop/src/utils/sessionConfig.ts +++ b/frontend/desktop/src/utils/sessionConfig.ts @@ -41,3 +41,7 @@ export const setInviterId = (id: string) => localStorage.setItem('inviterId', id export const getUserSemChannel = () => localStorage.getItem('sem_source'); export const setUserSemChannel = (s: string) => localStorage.setItem('sem_source', s); + +export const getBaiduId = () => localStorage.getItem('bd_vid'); + +export const setBaiduId = (id: string) => localStorage.setItem('bd_vid', id);