mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 15:25:58 +08:00
fix: stop auto retry login when web app return error (#18747)
This commit is contained in:
parent
d6c252d77e
commit
70ebfc064b
@ -11,6 +11,7 @@ import { setAccessToken } from '@/app/components/share/utils'
|
|||||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||||
import { SSOProtocol } from '@/types/feature'
|
import { SSOProtocol } from '@/types/feature'
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
|
import AppUnavailable from '@/app/components/base/app-unavailable'
|
||||||
|
|
||||||
const WebSSOForm: FC = () => {
|
const WebSSOForm: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -48,7 +49,7 @@ const WebSSOForm: FC = () => {
|
|||||||
router.push(redirectUrl)
|
router.push(redirectUrl)
|
||||||
}, [getAppCodeFromRedirectUrl, redirectUrl, router, tokenFromUrl])
|
}, [getAppCodeFromRedirectUrl, redirectUrl, router, tokenFromUrl])
|
||||||
|
|
||||||
const handleSSOLogin = async () => {
|
const handleSSOLogin = useCallback(async () => {
|
||||||
const appCode = getAppCodeFromRedirectUrl()
|
const appCode = getAppCodeFromRedirectUrl()
|
||||||
if (!appCode || !redirectUrl) {
|
if (!appCode || !redirectUrl) {
|
||||||
showErrorToast('redirect url or app code is invalid.')
|
showErrorToast('redirect url or app code is invalid.')
|
||||||
@ -74,7 +75,7 @@ const WebSSOForm: FC = () => {
|
|||||||
default:
|
default:
|
||||||
showErrorToast('SSO protocol is not supported.')
|
showErrorToast('SSO protocol is not supported.')
|
||||||
}
|
}
|
||||||
}
|
}, [getAppCodeFromRedirectUrl, redirectUrl, router, systemFeatures.webapp_auth.sso_config.protocol])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
@ -83,20 +84,26 @@ const WebSSOForm: FC = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokenFromUrl)
|
if (!tokenFromUrl) {
|
||||||
|
await handleSSOLogin()
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await processTokenAndRedirect()
|
await processTokenAndRedirect()
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
}, [message, processTokenAndRedirect, tokenFromUrl])
|
}, [message, processTokenAndRedirect, tokenFromUrl, handleSSOLogin])
|
||||||
if (tokenFromUrl)
|
if (tokenFromUrl)
|
||||||
return <div className='flex items-center justify-center h-full'><Loading /></div>
|
return <div className='flex items-center justify-center h-full'><Loading /></div>
|
||||||
|
if (message) {
|
||||||
|
return <div className='flex items-center justify-center h-full'>
|
||||||
|
<AppUnavailable code={'App Unavailable'} unknownReason={message} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
if (systemFeatures.webapp_auth.enabled) {
|
if (systemFeatures.webapp_auth.enabled) {
|
||||||
if (systemFeatures.webapp_auth.allow_sso) {
|
if (systemFeatures.webapp_auth.allow_sso) {
|
||||||
handleSSOLogin()
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center h-full">
|
<div className="flex items-center justify-center h-full">
|
||||||
<div className={cn('flex flex-col items-center w-full grow justify-center', 'px-6', 'md:px-[108px]')}>
|
<div className={cn('flex flex-col items-center w-full grow justify-center', 'px-6', 'md:px-[108px]')}>
|
||||||
|
@ -4,7 +4,7 @@ import React from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
type IAppUnavailableProps = {
|
type IAppUnavailableProps = {
|
||||||
code?: number
|
code?: number | string
|
||||||
isUnknownReason?: boolean
|
isUnknownReason?: boolean
|
||||||
unknownReason?: string
|
unknownReason?: string
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,8 @@ function unicodeToChar(text: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function requiredWebSSOLogin() {
|
function requiredWebSSOLogin(message?: string) {
|
||||||
globalThis.location.href = `/webapp-signin?redirect_url=${globalThis.location.pathname}`
|
globalThis.location.href = `/webapp-signin?redirect_url=${globalThis.location.pathname}&message=${message}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccessToken(isPublicAPI?: boolean) {
|
function getAccessToken(isPublicAPI?: boolean) {
|
||||||
@ -512,15 +512,9 @@ export const ssePost = (
|
|||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
res.json().then((data: any) => {
|
res.json().then((data: any) => {
|
||||||
if (isPublicAPI) {
|
if (isPublicAPI) {
|
||||||
if (data.code === 'web_app_access_denied') {
|
if (data.code === 'web_app_access_denied')
|
||||||
Toast.notify({
|
requiredWebSSOLogin(data.message)
|
||||||
type: 'error',
|
|
||||||
message: data.message,
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
|
||||||
requiredWebSSOLogin()
|
|
||||||
}, 1500)
|
|
||||||
}
|
|
||||||
if (data.code === 'web_sso_auth_required')
|
if (data.code === 'web_sso_auth_required')
|
||||||
requiredWebSSOLogin()
|
requiredWebSSOLogin()
|
||||||
|
|
||||||
@ -576,13 +570,7 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
|
|||||||
const { code, message } = errRespData
|
const { code, message } = errRespData
|
||||||
// webapp sso
|
// webapp sso
|
||||||
if (code === 'web_app_access_denied') {
|
if (code === 'web_app_access_denied') {
|
||||||
Toast.notify({
|
requiredWebSSOLogin(message)
|
||||||
type: 'error',
|
|
||||||
message,
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
|
||||||
requiredWebSSOLogin()
|
|
||||||
}, 1500)
|
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
}
|
}
|
||||||
if (code === 'web_sso_auth_required') {
|
if (code === 'web_sso_auth_required') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user