OAuth Login Promise Hangs Indefinitely When User Closes Popup

Aperta
#1,474 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@SatyamPandey-07 ci sta già lavorando.

Dal 29/11/2026.

  • #1475 di @SatyamPandey-07 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript, react

Direzione di ricerca

Start with packages/auth/src/loginWithRocketChatOAuth.ts, especially getRocketChatOAuthCredentials and its popup polling and message listener. Check the existing auth tests for coverage of OAuth popup callbacks and cancellation. Done when closing the popup rejects the promise, callback handling cleans up its listeners and interval, and malformed message data does not cause an error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

When authenticating via loginWithRocketChatOAuth(), getRocketChatOAuthCredentials in packages/auth/src/loginWithRocketChatOAuth.ts creates a Promise that only accepts resolve and never rejects if the user closes the OAuth popup window manually. Additionally, e.data.type is accessed without optional chaining and the interval/event listener are not immediately cleaned up when rc-oauth-callback is received.

Steps to Reproduce

  1. Configure EmbeddedChat with authFlow: 'OAUTH'.
  2. Click the Join / Sign in with Rocket.Chat OAuth button (triggers onJoin in packages/react/src/views/ChatInput/ChatInput.js, which calls await RCInstance.auth.loginWithRocketChatOAuth()).
  3. Close the opened OAuth popup window manually without completing authentication.
  4. Observe that the await never resolves or rejects, and no error toast or recovery state is triggered.

Expected Behavior

Closing the OAuth popup before authentication completes should clean up the polling interval and message event listener and reject the returned Promise with a descriptive error (e.g., "OAuth popup closed by user"), allowing callers' try/catch blocks to handle the cancellation.

Actual Behavior / Error Logs

No error is thrown; `getRocketChatOAuthCredentials` in `packages/auth/src/loginWithRocketChatOAuth.ts` (lines 45-67) clears `checkInterval` and removes the `message` listener when `popup.closed` is true, leaving the Promise permanently in a `pending` state.

Proposed Fix

Update getRocketChatOAuthCredentials in packages/auth/src/loginWithRocketChatOAuth.ts:

  • Add reject to the Promise executor and track a settled flag to prevent double-settlement.
  • Extract a shared cleanup() helper to call clearInterval(checkInterval) and window.removeEventListener("message", onMessage).
  • Call cleanup() and reject(new Error("OAuth popup closed by user")) when popup.closed is detected before settlement.
  • Call cleanup() immediately when rc-oauth-callback resolves, and use e.data?.type === "rc-oauth-callback" to guard against null/non-object postMessage payloads.
Lingua principale
JavaScript
Stelle
171
Fork
421
Merge medio
3g 6h
PR unite (30g)
4

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RocketChat/EmbeddedChat

Tutte le issue di RocketChat/EmbeddedChat

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.