RocketChat / RocketChat/EmbeddedChat

Bug: Secure token functions crash with TypeError — users on secure auth flow cannot log in or log out

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

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Description

In packages/react/src/lib/auth.js, the secure token storage functions (saveTokenSecure, getTokenSecure, deleteTokenSecure) reference this.handleSecureLogin(...) — but they are plain standalone async functions, not class methods. When invoked via getTokenStorage(secure: true), this is undefined in strict mode, causing an immediate TypeError crash. Any user or deployment configured to use the secure auth flow cannot log in or log out.

File: packages/react/src/lib/auth.js — lines 28–33

Steps to Reproduce
  1. Configure EmbeddedChat with secure: true (or any auth flow that calls getTokenStorage(true))
  2. Launch the app and attempt to log in
  3. Observe a TypeError: Cannot read properties of undefined (reading 'handleSecureLogin') in the browser console
  4. The user remains stuck on the login screen with no visible error message in the UI
Expected Behavior

Logging in and out should work correctly when the secure auth flow is configured. The token should be saved and deleted via the secure handler without any runtime errors.

Actual Behavior

A TypeError is thrown as soon as login is attempted on the secure flow:

The crash is thrown inside an async chain, so the UI shows no meaningful error — the user is silently stuck on the login screen or unable to log out.

Environment
  • Affects all environments where secure: true is configured
  • The localStorage (non-secure) auth path is completely unaffected
  • No specific OS or browser dependency
Additional Information

Root Cause:
deleteTokenSecure (and related functions) use this.handleSecureLogin(...), but are defined as plain async function declarations. In strict mode (enforced by all modern bundlers), this is undefined when these functions are called outside of a class/object context.

Buggy code:

async function deleteTokenSecure() {
  this.handleSecureLogin('delete'); // 💥 TypeError in strict mode
}

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start in packages/react/src/lib/auth.js at saveTokenSecure, getTokenSecure, deleteTokenSecure, and getTokenStorage(true); trace how the secure handler is obtained and reproduce the TypeError with secure authentication enabled. Done means secure login and logout save and delete tokens without the runtime error, while the localStorage path remains unaffected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.