mirror of
https://github.com/langgenius/dify.git
synced 2025-11-29 20:37:22 +00:00
fix: passport outdate caused webapp reload (#27175)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
e45d5700ec
commit
d6e7543ba6
@ -6,7 +6,6 @@ import { useWebAppStore } from '@/context/web-app-context'
|
|||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
import { useRouter, useSearchParams } from 'next/navigation'
|
||||||
import AppUnavailable from '@/app/components/base/app-unavailable'
|
import AppUnavailable from '@/app/components/base/app-unavailable'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { AccessMode } from '@/models/access-control'
|
|
||||||
import { webAppLoginStatus, webAppLogout } from '@/service/webapp-auth'
|
import { webAppLoginStatus, webAppLogout } from '@/service/webapp-auth'
|
||||||
import { fetchAccessToken } from '@/service/share'
|
import { fetchAccessToken } from '@/service/share'
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
@ -35,7 +34,6 @@ const Splash: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
router.replace(url)
|
router.replace(url)
|
||||||
}, [getSigninUrl, router, webAppLogout, shareCode])
|
}, [getSigninUrl, router, webAppLogout, shareCode])
|
||||||
|
|
||||||
const needCheckIsLogin = webAppAccessMode !== AccessMode.PUBLIC
|
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (message) {
|
if (message) {
|
||||||
@ -58,8 +56,8 @@ const Splash: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const { userLoggedIn, appLoggedIn } = await webAppLoginStatus(needCheckIsLogin, shareCode!)
|
// if access mode is public, user login is always true, but the app login(passport) may be expired
|
||||||
|
const { userLoggedIn, appLoggedIn } = await webAppLoginStatus(shareCode!)
|
||||||
if (userLoggedIn && appLoggedIn) {
|
if (userLoggedIn && appLoggedIn) {
|
||||||
redirectOrFinish()
|
redirectOrFinish()
|
||||||
}
|
}
|
||||||
@ -87,7 +85,6 @@ const Splash: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
router,
|
router,
|
||||||
message,
|
message,
|
||||||
webAppAccessMode,
|
webAppAccessMode,
|
||||||
needCheckIsLogin,
|
|
||||||
tokenFromUrl])
|
tokenFromUrl])
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
|
|||||||
@ -68,14 +68,14 @@ const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
updateShareCode(shareCode)
|
updateShareCode(shareCode)
|
||||||
}, [shareCode, updateShareCode])
|
}, [shareCode, updateShareCode])
|
||||||
|
|
||||||
const { isFetching, data: accessModeResult } = useGetWebAppAccessModeByCode(shareCode)
|
const { isLoading, data: accessModeResult } = useGetWebAppAccessModeByCode(shareCode)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (accessModeResult?.accessMode)
|
if (accessModeResult?.accessMode)
|
||||||
updateWebAppAccessMode(accessModeResult.accessMode)
|
updateWebAppAccessMode(accessModeResult.accessMode)
|
||||||
}, [accessModeResult, updateWebAppAccessMode, shareCode])
|
}, [accessModeResult, updateWebAppAccessMode, shareCode])
|
||||||
|
|
||||||
if (isGlobalPending || isFetching) {
|
if (isGlobalPending || isLoading) {
|
||||||
return <div className='flex h-full w-full items-center justify-center'>
|
return <div className='flex h-full w-full items-center justify-center'>
|
||||||
<Loading />
|
<Loading />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -30,14 +30,8 @@ type isWebAppLogin = {
|
|||||||
app_logged_in: boolean
|
app_logged_in: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function webAppLoginStatus(enabled: boolean, shareCode: string) {
|
export async function webAppLoginStatus(shareCode: string) {
|
||||||
if (!enabled) {
|
// always need to check login to prevent passport from being outdated
|
||||||
return {
|
|
||||||
userLoggedIn: true,
|
|
||||||
appLoggedIn: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check remotely, the access token could be in cookie (enterprise SSO redirected with https)
|
// check remotely, the access token could be in cookie (enterprise SSO redirected with https)
|
||||||
const { logged_in, app_logged_in } = await getPublic<isWebAppLogin>(`/login/status?app_code=${shareCode}`)
|
const { logged_in, app_logged_in } = await getPublic<isWebAppLogin>(`/login/status?app_code=${shareCode}`)
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user