OAuth Login Promise Hangs Indefinitely When User Closes Popup

Abierto
#1,474 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@SatyamPandey-07 ya está trabajando en esto.

Desde el 29/11/2026.

  • #1475 de @SatyamPandey-07 — abierto

Evaluación

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

Línea de trabajo

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.

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

Descripción

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.
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.