mirror of https://github.com/langgenius/dify.git
fix: web app throw error when app need login
This commit is contained in:
parent
80b017c94c
commit
ce2d000c5d
|
|
@ -11,6 +11,7 @@ import type { FC, PropsWithChildren } from 'react'
|
|||
import { useEffect } from 'react'
|
||||
import { useState } from 'react'
|
||||
import { create } from 'zustand'
|
||||
import { useGlobalPublicStore } from './global-public-context'
|
||||
|
||||
type WebAppStore = {
|
||||
shareCode: string | null
|
||||
|
|
@ -56,6 +57,7 @@ const getShareCodeFromPathname = (pathname: string): string | null => {
|
|||
}
|
||||
|
||||
const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
const isGlobalPending = useGlobalPublicStore(s => s.isGlobalPending)
|
||||
const updateWebAppAccessMode = useWebAppStore(state => state.updateWebAppAccessMode)
|
||||
const updateShareCode = useWebAppStore(state => state.updateShareCode)
|
||||
const pathname = usePathname()
|
||||
|
|
@ -67,7 +69,7 @@ const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
|||
updateShareCode(shareCode)
|
||||
|
||||
const { isFetching, data: accessModeResult } = useGetWebAppAccessModeByCode(shareCode)
|
||||
const [isFetchingAccessToken, setIsFetchingAccessToken] = useState(false)
|
||||
const [isFetchingAccessToken, setIsFetchingAccessToken] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (accessModeResult?.accessMode) {
|
||||
|
|
@ -84,7 +86,7 @@ const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
|||
}
|
||||
}, [accessModeResult, updateWebAppAccessMode, shareCode])
|
||||
|
||||
if (isFetching || isFetchingAccessToken) {
|
||||
if (isGlobalPending || isFetching || isFetchingAccessToken) {
|
||||
return <div className='flex h-full w-full items-center justify-center'>
|
||||
<Loading />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import { AccessMode } from '@/models/access-control'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { fetchAppInfo, fetchAppMeta, fetchAppParams, getAppAccessModeByAppCode } from './share'
|
||||
|
||||
const NAME_SPACE = 'webapp'
|
||||
|
||||
export const useGetWebAppAccessModeByCode = (code: string | null) => {
|
||||
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'appAccessMode', code],
|
||||
queryFn: () => {
|
||||
if (systemFeatures.webapp_auth.enabled === false) {
|
||||
return {
|
||||
accessMode: AccessMode.PUBLIC,
|
||||
}
|
||||
}
|
||||
if (!code || code.length === 0)
|
||||
return Promise.reject(new Error('App code is required to get access mode'))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue