Skip to content

Commit

Permalink
control login methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Aug 20, 2024
1 parent ec969d7 commit c6e500b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions frontend/desktop/src/api/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/desktop/src/components/signin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -247,7 +249,7 @@ export default function SigninComponent() {
? (t('common:loading') || 'Loading') + '...'
: t('common:log_in') || 'Log In'}
</Button>
<AuthList />
{hasBaiduToken && getBaiduId() ? <Box></Box> : <AuthList />}
</>
)}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion frontend/desktop/src/pages/api/platform/getAuthConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function genResAuthClientConfig(conf: AuthConfigType) {
}
},
proxyAddress: conf.proxyAddress || '',
baiduToken: conf.baiduToken || ''
hasBaiduToken: !!conf.baiduToken
};
return authClientConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/desktop/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion frontend/desktop/src/types/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type AuthConfigType = {
callbackURL: string;
signUpEnabled?: boolean;
baiduToken?: string;
hasBaiduToken?: boolean;
jwt: JwtConfigType;
billingUrl?: string;
workorderUrl?: string;
Expand Down Expand Up @@ -137,6 +138,7 @@ export type AuthClientConfigType = DeepRequired<
OmitPathArr<
AuthConfigType,
[
'baiduToken',
'signUpEnabled',
'invite.lafSecretKey',
'invite.lafBaseURL',
Expand Down Expand Up @@ -225,7 +227,7 @@ export const DefaultLayoutConfig: LayoutConfigType = {
};

export const DefaultAuthClientConfig: AuthClientConfigType = {
baiduToken: '',
hasBaiduToken: false,
invite: {
enabled: false
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/desktop/src/utils/sessionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit c6e500b

Please sign in to comment.