Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
ce2e926d
authored
Dec 19, 2024
by
heheer
Committed by
GitHub
Dec 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: add sso auto login config (#3436)
parent
bd79e770
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
packages/global/common/system/types/index.d.ts
+1
-0
projects/app/src/pages/login/components/LoginForm/components/FormLayout.tsx
+22
-4
projects/app/src/web/context/useInitApp.ts
+1
-1
No files found.
packages/global/common/system/types/index.d.ts
View file @
ce2e926d
...
@@ -58,6 +58,7 @@ export type FastGPTFeConfigsType = {
...
@@ -58,6 +58,7 @@ export type FastGPTFeConfigsType = {
icon
?:
string
;
icon
?:
string
;
title
?:
string
;
title
?:
string
;
url
?:
string
;
url
?:
string
;
autoLogin
?:
boolean
;
};
};
oauth
?:
{
oauth
?:
{
github
?:
string
;
github
?:
string
;
...
...
projects/app/src/pages/login/components/LoginForm/components/FormLayout.tsx
View file @
ce2e926d
...
@@ -6,7 +6,7 @@ import { OAuthEnum } from '@fastgpt/global/support/user/constant';
...
@@ -6,7 +6,7 @@ import { OAuthEnum } from '@fastgpt/global/support/user/constant';
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
import
{
customAlphabet
}
from
'nanoid'
;
import
{
customAlphabet
}
from
'nanoid'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
Dispatch
,
useMemo
,
useRef
}
from
'react'
;
import
{
Dispatch
,
use
Effect
,
use
Memo
,
useRef
}
from
'react'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
I18nLngSelector
from
'@/components/Select/I18nLngSelector'
;
import
I18nLngSelector
from
'@/components/Select/I18nLngSelector'
;
import
{
useSystem
}
from
'@fastgpt/web/hooks/useSystem'
;
import
{
useSystem
}
from
'@fastgpt/web/hooks/useSystem'
;
...
@@ -100,6 +100,26 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
...
@@ -100,6 +100,26 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
[feConfigs?.sso?.url, oAuthList.length]
[feConfigs?.sso?.url, oAuthList.length]
);
);
const formatUrl = useMemo(() => {
if (feConfigs?.sso?.url) {
return `
$
{
feConfigs
.
sso
.
url
}
/login/
oauth
/
authorize
?
redirect_uri
=
$
{
encodeURIComponent
(
redirectUri
)}
&
state
=
$
{
state
.
current
}
`;
}
return '';
}, [feConfigs.sso, redirectUri]);
useEffect(() => {
if (formatUrl && feConfigs?.sso?.autoLogin) {
setLoginStore({
provider: OAuthEnum.sso,
lastRoute,
state: state.current
});
window.open(formatUrl, '_self');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [feConfigs.sso]);
return (
return (
<Flex flexDirection={'column'} h={'100%'}>
<Flex flexDirection={'column'} h={'100%'}>
<Flex alignItems={'center'} justify={'space-between'}>
<Flex alignItems={'center'} justify={'space-between'}>
...
@@ -167,8 +187,7 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
...
@@ -167,8 +187,7 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
borderRadius={'sm'}
borderRadius={'sm'}
leftIcon={<MyImage alt="" src={feConfigs.sso.icon as any} w="20px" />}
leftIcon={<MyImage alt="" src={feConfigs.sso.icon as any} w="20px" />}
onClick={() => {
onClick={() => {
const url = feConfigs.sso?.url;
if (!formatUrl) {
if (!url) {
toast({
toast({
title: 'SSO URL is not set',
title: 'SSO URL is not set',
status: 'error'
status: 'error'
...
@@ -181,7 +200,6 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
...
@@ -181,7 +200,6 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
state: state.current
state: state.current
});
});
const formatUrl = `
$
{
url
}
/login/
oauth
/
authorize
?
redirect_uri
=
$
{
encodeURIComponent
(
redirectUri
)}
&
state
=
$
{
state
.
current
}
`;
window.open(formatUrl, '_self');
window.open(formatUrl, '_self');
}}
}}
>
>
...
...
projects/app/src/web/context/useInitApp.ts
View file @
ce2e926d
...
@@ -71,7 +71,7 @@ export const useInitApp = () => {
...
@@ -71,7 +71,7 @@ export const useInitApp = () => {
if
(
sourceDomain
)
return
sourceDomain
;
if
(
sourceDomain
)
return
sourceDomain
;
return
document
.
referrer
;
return
document
.
referrer
;
})();
})();
console
.
log
(
formatSourceDomain
,
'-=-='
);
if
(
formatSourceDomain
&&
!
sessionStorage
.
getItem
(
'sourceDomain'
))
{
if
(
formatSourceDomain
&&
!
sessionStorage
.
getItem
(
'sourceDomain'
))
{
sessionStorage
.
setItem
(
'sourceDomain'
,
formatSourceDomain
);
sessionStorage
.
setItem
(
'sourceDomain'
,
formatSourceDomain
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment