[PR #27524] Fix/27468 in dify 192 the iframe embed cannot pass the user id in system variable #31789

Closed
opened 2026-02-21 20:50:08 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/27524

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This pull request introduces and propagates support for "embedded user ID" and "embedded conversation ID" throughout the authentication and chatbot flows in the web application. The changes ensure that these IDs, when present (such as in embedded/iframe contexts), are hydrated from system variables and correctly passed to backend API calls for access token retrieval and session management. Comprehensive tests are also added to verify the correct handling of these IDs in both store hydration and authentication scenarios.

Support for embedded user/conversation IDs:

  • The WebAppStore now includes embeddedUserId and embeddedConversationId fields, along with corresponding update methods. These are hydrated from system variables using the getProcessedSystemVariablesFromUrlParams utility in the WebAppStoreProvider, and are cleared if not present. [1] [2] [3]
  • The useEmbeddedChatbot hook now uses embeddedUserId and embeddedConversationId from the store instead of fetching system variables directly, ensuring consistent propagation across the app.

Authentication flow updates:

  • Both the email/password (MailAndPasswordAuth) and email code (CheckCode) authentication components now pass embeddedUserId (when available) to the fetchAccessToken API call, ensuring the correct user context is used during login. [1] [2] [3] [4] [5] [6]
  • The Splash component also passes embeddedUserId to fetchAccessToken during session restoration, and now listens for changes to embeddedUserId to trigger effect updates. [1] [2] [3]

Testing enhancements:

  • New tests verify that the store hydrates and clears embeddedUserId and embeddedConversationId based on system variable presence.
  • Additional tests ensure that authentication flows correctly propagate embeddedUserId to API calls and session setup logic.

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/27524 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request introduces and propagates support for "embedded user ID" and "embedded conversation ID" throughout the authentication and chatbot flows in the web application. The changes ensure that these IDs, when present (such as in embedded/iframe contexts), are hydrated from system variables and correctly passed to backend API calls for access token retrieval and session management. Comprehensive tests are also added to verify the correct handling of these IDs in both store hydration and authentication scenarios. **Support for embedded user/conversation IDs:** * The `WebAppStore` now includes `embeddedUserId` and `embeddedConversationId` fields, along with corresponding update methods. These are hydrated from system variables using the `getProcessedSystemVariablesFromUrlParams` utility in the `WebAppStoreProvider`, and are cleared if not present. [[1]](diffhunk://#diff-3a86cc2e5e7499e0b60ee3c0c330efd5d5949d7f4429b5d0ea232ed0d78c3426R28-R31) [[2]](diffhunk://#diff-3a86cc2e5e7499e0b60ee3c0c330efd5d5949d7f4429b5d0ea232ed0d78c3426R47-R51) [[3]](diffhunk://#diff-3a86cc2e5e7499e0b60ee3c0c330efd5d5949d7f4429b5d0ea232ed0d78c3426R71-R106) * The `useEmbeddedChatbot` hook now uses `embeddedUserId` and `embeddedConversationId` from the store instead of fetching system variables directly, ensuring consistent propagation across the app. **Authentication flow updates:** * Both the email/password (`MailAndPasswordAuth`) and email code (`CheckCode`) authentication components now pass `embeddedUserId` (when available) to the `fetchAccessToken` API call, ensuring the correct user context is used during login. [[1]](diffhunk://#diff-6ae95b0cc410c57b043506c524431a6155cbe9215b700b3c05fb40ea7c3fd3ccR13) [[2]](diffhunk://#diff-6ae95b0cc410c57b043506c524431a6155cbe9215b700b3c05fb40ea7c3fd3ccR34) [[3]](diffhunk://#diff-6ae95b0cc410c57b043506c524431a6155cbe9215b700b3c05fb40ea7c3fd3ccL85-R90) [[4]](diffhunk://#diff-822a5b7386cd0bdba3059432879e10bce4ab84dee4fce88c66460eb3f9dc6327R15) [[5]](diffhunk://#diff-822a5b7386cd0bdba3059432879e10bce4ab84dee4fce88c66460eb3f9dc6327R27) [[6]](diffhunk://#diff-822a5b7386cd0bdba3059432879e10bce4ab84dee4fce88c66460eb3f9dc6327L66-R71) * The `Splash` component also passes `embeddedUserId` to `fetchAccessToken` during session restoration, and now listens for changes to `embeddedUserId` to trigger effect updates. [[1]](diffhunk://#diff-78ba539f75b26c22e705fa4182ad27dbadc3c90ea038734c32f8971c0498c9ddR18) [[2]](diffhunk://#diff-78ba539f75b26c22e705fa4182ad27dbadc3c90ea038734c32f8971c0498c9ddL72-R76) [[3]](diffhunk://#diff-78ba539f75b26c22e705fa4182ad27dbadc3c90ea038734c32f8971c0498c9ddL88-R93) **Testing enhancements:** * New tests verify that the store hydrates and clears `embeddedUserId` and `embeddedConversationId` based on system variable presence. * Additional tests ensure that authentication flows correctly propagate `embeddedUserId` to API calls and session setup logic. ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:08 -05:00
yindo closed this issue 2026-02-21 20:50:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31789