mirror of
https://github.com/langgenius/dify.git
synced 2026-02-09 23:20:12 -05:00
Fix/27468 in dify 192 the iframe embed cannot pass the user id in system variable (#27524)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import { usePathname, useSearchParams } from 'next/navigation'
|
||||
import type { FC, PropsWithChildren } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import { create } from 'zustand'
|
||||
import { getProcessedSystemVariablesFromUrlParams } from '@/app/components/base/chat/utils'
|
||||
import { useGlobalPublicStore } from './global-public-context'
|
||||
|
||||
type WebAppStore = {
|
||||
@@ -24,6 +25,10 @@ type WebAppStore = {
|
||||
updateWebAppMeta: (appMeta: AppMeta | null) => void
|
||||
userCanAccessApp: boolean
|
||||
updateUserCanAccessApp: (canAccess: boolean) => void
|
||||
embeddedUserId: string | null
|
||||
updateEmbeddedUserId: (userId: string | null) => void
|
||||
embeddedConversationId: string | null
|
||||
updateEmbeddedConversationId: (conversationId: string | null) => void
|
||||
}
|
||||
|
||||
export const useWebAppStore = create<WebAppStore>(set => ({
|
||||
@@ -39,6 +44,11 @@ export const useWebAppStore = create<WebAppStore>(set => ({
|
||||
updateWebAppMeta: (appMeta: AppMeta | null) => set(() => ({ appMeta })),
|
||||
userCanAccessApp: false,
|
||||
updateUserCanAccessApp: (canAccess: boolean) => set(() => ({ userCanAccessApp: canAccess })),
|
||||
embeddedUserId: null,
|
||||
updateEmbeddedUserId: (userId: string | null) => set(() => ({ embeddedUserId: userId })),
|
||||
embeddedConversationId: null,
|
||||
updateEmbeddedConversationId: (conversationId: string | null) =>
|
||||
set(() => ({ embeddedConversationId: conversationId })),
|
||||
}))
|
||||
|
||||
const getShareCodeFromRedirectUrl = (redirectUrl: string | null): string | null => {
|
||||
@@ -58,9 +68,12 @@ const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
const isGlobalPending = useGlobalPublicStore(s => s.isGlobalPending)
|
||||
const updateWebAppAccessMode = useWebAppStore(state => state.updateWebAppAccessMode)
|
||||
const updateShareCode = useWebAppStore(state => state.updateShareCode)
|
||||
const updateEmbeddedUserId = useWebAppStore(state => state.updateEmbeddedUserId)
|
||||
const updateEmbeddedConversationId = useWebAppStore(state => state.updateEmbeddedConversationId)
|
||||
const pathname = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
const redirectUrlParam = searchParams.get('redirect_url')
|
||||
const searchParamsString = searchParams.toString()
|
||||
|
||||
// Compute shareCode directly
|
||||
const shareCode = getShareCodeFromRedirectUrl(redirectUrlParam) || getShareCodeFromPathname(pathname)
|
||||
@@ -68,6 +81,29 @@ const WebAppStoreProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
updateShareCode(shareCode)
|
||||
}, [shareCode, updateShareCode])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const syncEmbeddedUserId = async () => {
|
||||
try {
|
||||
const { user_id, conversation_id } = await getProcessedSystemVariablesFromUrlParams()
|
||||
if (!cancelled) {
|
||||
updateEmbeddedUserId(user_id || null)
|
||||
updateEmbeddedConversationId(conversation_id || null)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
if (!cancelled) {
|
||||
updateEmbeddedUserId(null)
|
||||
updateEmbeddedConversationId(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
syncEmbeddedUserId()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [searchParamsString, updateEmbeddedUserId, updateEmbeddedConversationId])
|
||||
|
||||
const { isLoading, data: accessModeResult } = useGetWebAppAccessModeByCode(shareCode)
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user