mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
feat: SSO (#2414)
* 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:
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -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>
|
||||
</>
|
||||
)}
|
||||
|
47
projects/app/src/pages/login/sso.tsx
Normal file
47
projects/app/src/pages/login/sso.tsx
Normal 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;
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user