specify user id for the web app
Self Checks
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to file this report (我已阅读并同意 Language Policy).
1. Is this request related to a challenge you're experiencing?
I tried to specify a user ID when using a web app, but it failed. The scenario involves embedding the web app into a webpage (for example, using an iframe), and my goal is to integrate an existing user ID into the web app. This way, I can track and identify the user's input and output.
2. Describe the feature you'd like to see
Maybe Dify could enable the system to pass a user ID somehow, like app.dify.ai/chat/xxxx?user_id=1111
3. How will this feature improve your workflow or experience?
I can track and identify the user's input and output, which will help us better understand user behaviors.
4. Additional context or comments
No response
5. Can you help us with this feature?
- [X] I am interested in contributing to this feature.
🤖
Thank you for your feature request. It's indeed a valuable addition to be able to pass a user ID for tracking and identification purposes when embedding the Dify web app into a webpage.
Currently, Dify handles user identification through a combination of session management, token-based authentication, and role-based access control. You can find more details about this in the login.py file in the Dify repository.
To implement your feature request, we would need to modify the Chat component to accept a userId prop. This prop can then be used wherever user identification is required. Here's a basic example of how this could be done:
export type IChatProps = {
// ...existing props
userId?: string
}
const Chat: FC<IChatProps> = ({
// ...existing props
userId,
}) => {
// ...existing component code
}
In this example, userId is an optional prop. If a user ID is provided when the Chat component is used, it will be available in the component as userId. You can then use this userId for tracking and identification of user's input and output.
Please note that this is just a basic example. Depending on your specific requirements, you might need to make additional modifications to your code. For example, you might need to pass the userId to the onSend function or use it in other parts of your code where user identification is required.
You can find the Chat component in the web/app/components/app/chat/index.tsx file in the Dify repository.
Since you've expressed interest in contributing to this feature, I would recommend starting with these modifications and then testing to see if they meet your needs. If you encounter any issues or have further questions, feel free to ask.
Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Close due to it's no longer active, if you have any questions, you can reopen it.