Bug: username fallback in updateUserUsername never runs since the ddp-client migration
Maintainers usually reply within 1 day
@MuhammadFaizan-prog is already working on this.
Since Dec 4, 2026.
- #1490 by @MuhammadFaizan-prog — open
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, react
- Domain
- authentication, backend
Research direction
Start in packages/api/src/EmbeddedChatApi.ts, at updateUserUsername() and _restRequest(), and check how the API client rejects 400 responses. Compare that error shape with the server's error-could-not-save-identity response described in the issue. Update the error handling so the username suggestion fallback runs for that response, then verify that a taken username triggers the fallback and other errors remain logged.
Written by the indexing model from the issue text.
Description
Description:
Users who log in without a username (for example through Google SSO) go through updateUserUsername() in packages/api/src/EmbeddedChatApi.ts (lines 500 to 519). It turns the display name into a username and saves it with users.update. If that username is already taken, the catch block checks err?.errorType === "error-could-not-save-identity" and falls back to updateUserNameThroughSuggestion().
Since #1308 the request goes through _restRequest(), which calls this.sdk.rest.send(). In @rocket.chat/api-client 0.2.56 (the version yarn.lock resolves), send() rejects with the raw Response object on a 400, not the parsed JSON body:
if (response.ok) { return response; }
if (response.status !== 400) { return Promise.reject(response); }
// ...2FA retry check...
return Promise.reject(response);
So err is a Response, err.errorType is always undefined, and the fallback never runs. The error is only logged, and it shows up as [object Response].
On the server side, a taken username on users.update does produce that error type: _setUsername() returns false when checkUsernameAvailability() fails, and saveUser() turns that into a 400 with errorType: "error-could-not-save-identity".
Before #1308 this worked, because the code called fetch directly and read result.errorType from await response.json().
Steps to reproduce:
- Have a user whose display name maps to a username that already exists (for example display name "John Doe" while
john.doeis taken). - Log that user in through an SSO provider that creates the account without a username.
updateUserUsername()callsusers.updatewithjohn.doe, and the server answers 400error-could-not-save-identity.
Expected behavior:
The catch block sees errorType: "error-could-not-save-identity" and sets a username from users.getUsernameSuggestion, as it did before #1308.
Actual behavior:
The fallback is skipped. The user is left without a username and the console shows [object Response].
A possible fix is to read the body in the catch, for example const body = err instanceof Response ? await err.json().catch(() => ({})) : err; and check body?.errorType, or to do that once in _restRequest() so every caller gets the parsed error.
This is not the regex anchor problem in the same function, which #1201, #1202 and #1388 already cover. Found by reading the code against @rocket.chat/api-client 0.2.56 and Rocket.Chat develop; I have not reproduced it against a live server.
- Dominant language
- JavaScript
- Stars
- 171
- Forks
- 421
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing 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.
More from RocketChat/EmbeddedChat
-
[Bug]: Low contrast on color swatch borders in Theme Lab (Layout Editor)Possibly taken @yashsarvaiya45 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
RocketChat/EmbeddedChat#1486 ·
Maintainers usually reply within 1 day
-
bug(api): _doConnect swallows connection/auth errors and marks failed sessions as authenticatedPossibly taken @ashwanisingh011 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
RocketChat/EmbeddedChat#1484 ·
Maintainers usually reply within 1 day
-
Bug: White screen crash (`Cannot read properties of undefined (reading 'members')`) when rendering UserMention outside MarkupInteractionContextPossibly taken @swarnendusahu10-dotcom claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RocketChat/EmbeddedChat#1482 ·
Maintainers usually reply within 1 day
-
Bug: UIKit PreviewBlock cover image tiles repeatedly and stretches across viewport when zoomed outPossibly taken @swarnendusahu10-dotcom claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
RocketChat/EmbeddedChat#1480 · 1 comment ·
Maintainers usually reply within 1 day
-
ug(react): guard against null childElement in MessageAggregator setJumpToMessagePossibly taken @Suraj704-glitch claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
RocketChat/EmbeddedChat#1478 ·
Maintainers usually reply within 1 day
All issues in RocketChat/EmbeddedChat
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quasarframework/quasar#18614 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
microsoft/monaco-editor#5626 ·
Maintainers usually reply within 1 day
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
521xueweihan/HelloGitHub#4714 ·