Bug: username fallback in updateUserUsername never runs since the ddp-client migration

Abierto Apto para principiantes
#1,489 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@MuhammadFaizan-prog ya está trabajando en esto.

Desde el 4/12/2026.

  • #1490 de @MuhammadFaizan-prog — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, react

Línea de trabajo

Empieza en packages/api/src/EmbeddedChatApi.ts, en updateUserUsername() y _restRequest(), y comprueba cómo el cliente de la API rechaza las respuestas 400. Compara esa estructura de error con la respuesta del servidor error-could-not-save-identity descrita en el issue. Actualiza el manejo de errores para que el fallback de sugerencia de nombre de usuario se ejecute ante esa respuesta. Después, verifica que un nombre de usuario ya ocupado active el fallback y que los demás errores sigan registrándose.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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:
  1. Have a user whose display name maps to a username that already exists (for example display name "John Doe" while john.doe is taken).
  2. Log that user in through an SSO provider that creates the account without a username.
  3. updateUserUsername() calls users.update with john.doe, and the server answers 400 error-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.

Lenguaje dominante
JavaScript
Estrellas
171
Forks
421
Merge medio
3 d 6 h
PR fusionados (30 d)
4

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de RocketChat/EmbeddedChat

Todos los issues de RocketChat/EmbeddedChat

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.