Skip to content

Commit 8c81e75

Browse files
ctrlz526dreamer6680
authored andcommitted
Enhance WeChat login functionality (labring#5213)
* Enhance WeChat login functionality * Add inviterId
1 parent 59ed339 commit 8c81e75

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

packages/global/support/user/api.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export type OauthLoginProps = {
2121
export type WxLoginProps = {
2222
inviterId?: string;
2323
code: string;
24+
bd_vid?: string;
25+
msclkid?: string;
26+
fastgpt_sem?: string;
27+
sourceDomain?: string;
2428
};
2529

2630
export type FastLoginProps = {

projects/app/src/pageComponents/login/LoginForm/WechatForm.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import FormLayout from './FormLayout';
1010
import { useTranslation } from 'next-i18next';
1111
import Loading from '@fastgpt/web/components/common/MyLoading';
1212
import MyImage from '@fastgpt/web/components/common/Image/MyImage';
13+
import {
14+
getBdVId,
15+
getFastGPTSem,
16+
getMsclkid,
17+
getSourceDomain,
18+
removeFastGPTSem,
19+
getInviterId
20+
} from '@/web/support/marketing/utils';
1321

1422
interface Props {
1523
loginSuccess: (e: ResLogin) => void;
@@ -29,15 +37,28 @@ const WechatForm = ({ setPageType, loginSuccess }: Props) => {
2937
}
3038
});
3139

32-
useQuery(['getWXLoginResult', wechatInfo?.code], () => getWXLoginResult(wechatInfo?.code || ''), {
33-
refetchInterval: 3 * 1000,
34-
enabled: !!wechatInfo?.code,
35-
onSuccess(data: ResLogin | undefined) {
36-
if (data) {
37-
loginSuccess(data);
40+
useQuery(
41+
['getWXLoginResult', wechatInfo?.code],
42+
() =>
43+
getWXLoginResult({
44+
inviterId: getInviterId(),
45+
code: wechatInfo?.code || '',
46+
bd_vid: getBdVId(),
47+
msclkid: getMsclkid(),
48+
fastgpt_sem: getFastGPTSem(),
49+
sourceDomain: getSourceDomain()
50+
}),
51+
{
52+
refetchInterval: 3 * 1000,
53+
enabled: !!wechatInfo?.code,
54+
onSuccess(data: ResLogin | undefined) {
55+
if (data) {
56+
removeFastGPTSem();
57+
loginSuccess(data);
58+
}
3859
}
3960
}
40-
});
61+
);
4162

4263
return (
4364
<FormLayout setPageType={setPageType} pageType={LoginPageTypeEnum.wechat}>

projects/app/src/pages/login/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,10 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
9090

9191
/* default login type */
9292
useEffect(() => {
93-
const bd_vid = getBdVId();
94-
if (bd_vid) {
95-
setPageType(LoginPageTypeEnum.passwordLogin);
96-
return;
97-
}
93+
//delete bd_vid and show WeChat login
9894
setPageType(
9995
feConfigs?.oauth?.wechat ? LoginPageTypeEnum.wechat : LoginPageTypeEnum.passwordLogin
10096
);
101-
10297
// init store
10398
setLastChatAppId('');
10499
}, [feConfigs?.oauth, setLastChatAppId]);

projects/app/src/web/support/user/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
GetWXLoginQRResponse
1616
} from '@fastgpt/global/support/user/login/api.d';
1717
import type { preLoginResponse } from '@/pages/api/support/user/account/preLogin';
18+
import type { WxLoginProps } from '@fastgpt/global/support/user/api.d';
1819

1920
export const sendAuthCode = (data: {
2021
username: string;
@@ -99,8 +100,8 @@ export const putUserInfo = (data: UserUpdateParams) => PUT('/support/user/accoun
99100
export const getWXLoginQR = () =>
100101
GET<GetWXLoginQRResponse>('/proApi/support/user/account/login/wx/getQR');
101102

102-
export const getWXLoginResult = (code: string) =>
103-
GET<ResLogin>(`/proApi/support/user/account/login/wx/getResult`, { code });
103+
export const getWXLoginResult = (params: WxLoginProps) =>
104+
GET<ResLogin>(`/proApi/support/user/account/login/wx/getResult`, params);
104105

105106
export const getCaptchaPic = (username: string) =>
106107
GET<{

0 commit comments

Comments
 (0)