bug(api): _doConnect swallows connection/auth errors and marks failed sessions as authenticated

Open Beginner friendly
#1,484 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ashwanisingh011 is already working on this.

Since Dec 3, 2026.

  • #1485 by @ashwanisingh011 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, react

Research direction

Read packages/api/src/EmbeddedChatApi.ts and packages/react/src/views/EmbeddedChat.js to trace how connection errors reach the authentication state. Check the connect flow for failures from the connection, login, and stream subscriptions, then run the relevant tests or add coverage for rejected connections. Done means failed connections reject and do not mark the user authenticated.

Written by the indexing model from the issue text.

Description

bug
Description:

In packages/api/src/EmbeddedChatApi.ts, _doConnect() catches errors from this.sdk.connection.connect(), this.sdk.account.loginWithToken(), and stream subscriptions, calls this.close(), and never rethrows the error.

Because _doConnect() resolves with undefined instead of rejecting, RCInstance.connect(isChannelPrivate).then(...) in packages/react/src/views/EmbeddedChat.js still executes and sets isUserAuthenticated(true) even though the DDP connection failed and was closed.

Steps to reproduce:
  1. Instantiate EmbeddedChatApi and trigger api.connect() while sdk.connection.connect() or sdk.account.loginWithToken() fails/rejects.
  2. Observe that api.connect() resolves normally instead of rejecting.
  3. In EmbeddedChat.js, .then() runs and marks isUserAuthenticated as true with no active DDP subscriptions.
Expected behavior:

_doConnect() should clean up via await this.close() and rethrow the error so connect() rejects and EmbeddedChat does not mark a failed connection as authenticated.

Actual behavior:

connect() resolves silently and EmbeddedChat logs "Connected to RocketChat ..." and sets isUserAuthenticated(true) on a closed socket.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RocketChat/EmbeddedChat

All issues in RocketChat/EmbeddedChat

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.