Skip to content

Commit e87d657

Browse files
feat: display cancellation reason
Signed-off-by: Patrick Chin <8509935+thepatrickchin@users.noreply.github.com>
1 parent 824f449 commit e87d657

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

components/Chat/Chat.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export const Chat = () => {
229229
const [interactionMessage, setInteractionMessage] = useState(null);
230230
const webSocketRef = useRef<WebSocket | null>(null);
231231
const webSocketConnectedRef = useRef(false);
232+
const oauthPopupCancelledRef = useRef(false);
232233
const webSocketModeRef = useRef(
233234
sessionStorage.getItem('webSocketMode') === 'false' ? false : webSocketMode
234235
);
@@ -522,7 +523,7 @@ export const Chat = () => {
522523
const popup = window.open(
523524
oauthUrl,
524525
'oauth-popup',
525-
'width=600,height=700,scrollbars=yes,resizable=yes,noopener,noreferrer'
526+
'noopener,noreferrer'
526527
);
527528
const handleOAuthComplete = (event: MessageEvent) => {
528529
if (popup && !popup.closed) popup.close();
@@ -765,8 +766,17 @@ export const Chat = () => {
765766
if (isValidConsentPromptURL(oauthUrl)) {
766767
const shouldUsePopup = message?.content?.use_popup !== false;
767768
if (shouldUsePopup) {
769+
if (oauthPopupCancelledRef.current) return;
768770
// Open the validated OAuth URL in a new tab
769-
window.open(oauthUrl, '_blank', 'noopener,noreferrer');
771+
const popup = window.open(oauthUrl, 'oauth-popup', 'noopener,noreferrer');
772+
const handleOAuthComplete = (event: MessageEvent) => {
773+
if (popup && !popup.closed) popup.close();
774+
window.removeEventListener('message', handleOAuthComplete);
775+
if (event.data?.type === 'AUTH_CANCELLED') {
776+
oauthPopupCancelledRef.current = true;
777+
}
778+
};
779+
window.addEventListener('message', handleOAuthComplete);
770780
} else {
771781
persistOAuthPendingMessage();
772782
window.location.href = oauthUrl;
@@ -852,6 +862,7 @@ export const Chat = () => {
852862
const handleSend = useCallback(
853863
async (message: Message, deleteCount = 0, retry = false) => {
854864
message.id = uuidv4();
865+
oauthPopupCancelledRef.current = false;
855866

856867
// Set the active user message ID for WebSocket message tracking
857868
activeUserMessageId.current = message.id;

0 commit comments

Comments
 (0)