mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 07:31:19 +00:00
Enhance WeChat login functionality (#5213)
* Enhance WeChat login functionality * Add inviterId
This commit is contained in:
4
packages/global/support/user/api.d.ts
vendored
4
packages/global/support/user/api.d.ts
vendored
@@ -21,6 +21,10 @@ export type OauthLoginProps = {
|
||||
export type WxLoginProps = {
|
||||
inviterId?: string;
|
||||
code: string;
|
||||
bd_vid?: string;
|
||||
msclkid?: string;
|
||||
fastgpt_sem?: string;
|
||||
sourceDomain?: string;
|
||||
};
|
||||
|
||||
export type FastLoginProps = {
|
||||
|
@@ -10,6 +10,14 @@ import FormLayout from './FormLayout';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import Loading from '@fastgpt/web/components/common/MyLoading';
|
||||
import MyImage from '@fastgpt/web/components/common/Image/MyImage';
|
||||
import {
|
||||
getBdVId,
|
||||
getFastGPTSem,
|
||||
getMsclkid,
|
||||
getSourceDomain,
|
||||
removeFastGPTSem,
|
||||
getInviterId
|
||||
} from '@/web/support/marketing/utils';
|
||||
|
||||
interface Props {
|
||||
loginSuccess: (e: ResLogin) => void;
|
||||
@@ -29,15 +37,28 @@ const WechatForm = ({ setPageType, loginSuccess }: Props) => {
|
||||
}
|
||||
});
|
||||
|
||||
useQuery(['getWXLoginResult', wechatInfo?.code], () => getWXLoginResult(wechatInfo?.code || ''), {
|
||||
refetchInterval: 3 * 1000,
|
||||
enabled: !!wechatInfo?.code,
|
||||
onSuccess(data: ResLogin | undefined) {
|
||||
if (data) {
|
||||
loginSuccess(data);
|
||||
useQuery(
|
||||
['getWXLoginResult', wechatInfo?.code],
|
||||
() =>
|
||||
getWXLoginResult({
|
||||
inviterId: getInviterId(),
|
||||
code: wechatInfo?.code || '',
|
||||
bd_vid: getBdVId(),
|
||||
msclkid: getMsclkid(),
|
||||
fastgpt_sem: getFastGPTSem(),
|
||||
sourceDomain: getSourceDomain()
|
||||
}),
|
||||
{
|
||||
refetchInterval: 3 * 1000,
|
||||
enabled: !!wechatInfo?.code,
|
||||
onSuccess(data: ResLogin | undefined) {
|
||||
if (data) {
|
||||
removeFastGPTSem();
|
||||
loginSuccess(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return (
|
||||
<FormLayout setPageType={setPageType} pageType={LoginPageTypeEnum.wechat}>
|
||||
|
@@ -90,15 +90,10 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
|
||||
|
||||
/* default login type */
|
||||
useEffect(() => {
|
||||
const bd_vid = getBdVId();
|
||||
if (bd_vid) {
|
||||
setPageType(LoginPageTypeEnum.passwordLogin);
|
||||
return;
|
||||
}
|
||||
//delete bd_vid and show WeChat login
|
||||
setPageType(
|
||||
feConfigs?.oauth?.wechat ? LoginPageTypeEnum.wechat : LoginPageTypeEnum.passwordLogin
|
||||
);
|
||||
|
||||
// init store
|
||||
setLastChatAppId('');
|
||||
}, [feConfigs?.oauth, setLastChatAppId]);
|
||||
|
@@ -15,6 +15,7 @@ import type {
|
||||
GetWXLoginQRResponse
|
||||
} from '@fastgpt/global/support/user/login/api.d';
|
||||
import type { preLoginResponse } from '@/pages/api/support/user/account/preLogin';
|
||||
import type { WxLoginProps } from '@fastgpt/global/support/user/api.d';
|
||||
|
||||
export const sendAuthCode = (data: {
|
||||
username: string;
|
||||
@@ -99,8 +100,8 @@ export const putUserInfo = (data: UserUpdateParams) => PUT('/support/user/accoun
|
||||
export const getWXLoginQR = () =>
|
||||
GET<GetWXLoginQRResponse>('/proApi/support/user/account/login/wx/getQR');
|
||||
|
||||
export const getWXLoginResult = (code: string) =>
|
||||
GET<ResLogin>(`/proApi/support/user/account/login/wx/getResult`, { code });
|
||||
export const getWXLoginResult = (params: WxLoginProps) =>
|
||||
GET<ResLogin>(`/proApi/support/user/account/login/wx/getResult`, params);
|
||||
|
||||
export const getCaptchaPic = (username: string) =>
|
||||
GET<{
|
||||
|
Reference in New Issue
Block a user