RocketChat / RocketChat/Rocket.Chat
fix(omnichannel): prevent duplicate agent addition with client-side validation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description:
When adding an agent in Omnichannel > Agents, if a user who is already an agent is selected and "Add agent" is clicked:
- The API call was still being made.
- A success toast "Agent added" was incorrectly shown.
- No feedback was given to the user that the agent already exists.
This happens because there was no client-side validation before making the POST call to /v1/livechat/users/agent. The server returns 200 OK even for duplicate agent additions, so onError never triggers and the success flow runs regardless.
Steps to reproduce:
- Go to Omnichannel > Agents
- Add any user as an agent
- Try adding the same user again
- Notice that after adding the same user again "Agent added" success toast appears incorrectly.
Expected behavior:
when a user clicks on Add Agent and if the agent already exists in the Agent table then adding a same agent should show an error toast "User is already an agent" and no API call should be made.
Actual behavior:
A success toast "Agent added" appears and the API call is made even though the user is already an agent. This is caused by the absence of any duplicate check before calling the mutation:
const handleSave = useEffectEvent(async () => {
await saveAction({ username }); // ← no duplicate check
});
Selected the Agent we want to add:
When clicked on Add Agent:
Note -That the Add Agent toast appears incorrectly.
After fix — "User is already an agent" error toast appears and no API call is made:
Server Setup Information:
- Version of Rocket.Chat Server: version: 8.2.0-develop
- License Type: MIT
- Number of Users: Local Dev Instance
- Operating System: MacOS
- Deployment Method: Local development (meteor)
- Number of Running Instances: 1
- DB Replicaset Oplog: N/A (local dev)
- NodeJS Version: 22.16.0
- MongoDB Version: 8.0.12
Client Setup Information
- Desktop App or Browser Version:Chrome (latest)
- Operating System:MacOS Sequoia
Please Note - I have identified this issue and I am actively working on a fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Omnichannel > Agents client entry point and inspect handleSave, saveAction, and the POST /v1/livechat/users/agent flow. Reproduce the issue by adding a user twice; done means the second attempt shows "User is already an agent" and makes no API call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100