* feat: sso button

* feat: sso

* feat: sso callback url should be a page

* feat: sso redirect page

* chore: sso fe adjusting
This commit is contained in:
Finley Ge
2024-08-20 17:09:29 +08:00
committed by GitHub
parent 226cae5ab9
commit 2d0e6bd085
5 changed files with 70 additions and 0 deletions

View File

@@ -45,6 +45,11 @@ export type FastGPTFeConfigsType = {
isPlus?: boolean;
show_phoneLogin?: boolean;
show_emailLogin?: boolean;
sso?: {
icon?: string;
title?: string;
url?: string;
};
oauth?: {
github?: string;
google?: string;

View File

@@ -9,6 +9,7 @@ const unAuthPage: { [key: string]: boolean } = {
'/login': true,
'/login/provider': true,
'/login/fastlogin': true,
'/login/sso': true,
'/appStore': true,
'/chat/share': true,
'/chat/team': true,

View File

@@ -126,6 +126,22 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
</Button>
</Box>
))}
{feConfigs?.sso && (
<Box mt={4} color={'primary.700'} cursor={'pointer'} textAlign={'center'}>
<Button
variant={'whitePrimary'}
w={'100%'}
h={'42px'}
leftIcon={<Image alt="" src={feConfigs.sso.icon as any} w="20px" />}
onClick={() => {
feConfigs.sso?.url && router.replace(feConfigs.sso?.url, '_self');
}}
>
{feConfigs.sso.title}
</Button>
</Box>
)}
</Box>
</>
)}

View File

@@ -0,0 +1,47 @@
import React, { useCallback, useEffect, useMemo } from 'react';
import { useRouter } from 'next/router';
import type { ResLogin } from '@/global/support/api/userRes.d';
import { useChatStore } from '@/web/core/chat/context/storeChat';
import { useUserStore } from '@/web/support/user/useUserStore';
import { clearToken, setToken } from '@/web/support/user/auth';
import { ssoLogin } from '@/web/support/user/api';
import Loading from '@fastgpt/web/components/common/MyLoading';
import { useTranslation } from 'next-i18next';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
const provider = () => {
const { t } = useTranslation();
const { setLastChatId, setLastChatAppId } = useChatStore();
const { setUserInfo } = useUserStore();
const router = useRouter();
const { query } = router;
const loginSuccess = useCallback(
(res: ResLogin) => {
console.log('loginSuccess', res);
setToken(res.token);
setUserInfo(res.user);
// init store
setLastChatId('');
setLastChatAppId('');
router.push('/app/list');
},
[setLastChatId, setLastChatAppId, setUserInfo, router]
);
const { run: handleSSO } = useRequest2(() => ssoLogin(query), {
onSuccess: loginSuccess,
errorToast: t('common:support.user.login.error')
});
useEffect(() => {
if (query && Object.keys(query).length > 0) {
clearToken();
handleSSO();
}
}, [handleSSO, query]);
return <Loading />;
};
export default provider;

View File

@@ -23,6 +23,7 @@ export const oauthLogin = (params: OauthLoginProps) =>
POST<ResLogin>('/proApi/support/user/account/login/oauth', params);
export const postFastLogin = (params: FastLoginProps) =>
POST<ResLogin>('/proApi/support/user/account/login/fastLogin', params);
export const ssoLogin = (params: any) => GET<ResLogin>('/proApi/support/user/account/sso', params);
export const postRegister = ({
username,