OAuth Login Promise Hangs Indefinitely When User Closes Popup

Ouverte
#1,474 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@SatyamPandey-07 y travaille déjà.

Depuis le 29/11/2026.

  • #1475 par @SatyamPandey-07 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
javascript, react

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
JavaScript
Étoiles
171
Forks
421
Merge moyen
3 j 6 h
PR mergées (30 j)
4

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de RocketChat/EmbeddedChat

Toutes les issues de RocketChat/EmbeddedChat

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.