@@ -375,6 +375,16 @@ export const Chat = () => {
375375 wsUrl += `${ wsUrl . includes ( '?' ) ? '&' : '?' } conversation_id=${ encodeURIComponent ( conversationId ) } ` ;
376376 }
377377
378+ // Skip pre-auth if the user previously declined it OR is returning from a cancelled OAuth
379+ // right now. The oauth_auth_error param is checked directly because the cleanup effect
380+ // (which sets oauth_pre_auth_declined) runs after this effect due to declaration order.
381+ const currentUrlParams = new URLSearchParams ( window . location . search ) ;
382+ const preAuthDeclined = sessionStorage . getItem ( 'oauth_pre_auth_declined' ) === 'true'
383+ || ( ! ! currentUrlParams . get ( 'oauth_auth_error' ) && ! sessionStorage . getItem ( 'oauth_pending_message' ) ) ;
384+ if ( preAuthDeclined ) {
385+ wsUrl += `${ wsUrl . includes ( '?' ) ? '&' : '?' } skip_pre_auth=true` ;
386+ }
387+
378388 // Append custom parameters from settings (query + headers encoded for proxy)
379389 const customParamsRaw = sessionStorage . getItem ( 'webSocketCustomParams' ) ;
380390 if ( customParamsRaw ?. trim ( ) ) {
@@ -1514,12 +1524,27 @@ export const Chat = () => {
15141524
15151525 const pendingMessageRaw = sessionStorage . getItem ( 'oauth_pending_message' ) ;
15161526 const pendingConversationId = sessionStorage . getItem ( 'oauth_pending_conversation_id' ) ;
1517- if ( ! pendingMessageRaw || ! pendingConversationId ) return ;
1527+ if ( ! pendingMessageRaw || ! pendingConversationId ) {
1528+ // No pending message means this was a page-load pre-auth.
1529+ if ( authError ) {
1530+ // User declined pre-auth; skip it on reconnect to avoid a redirect loop.
1531+ sessionStorage . setItem ( 'oauth_pre_auth_declined' , 'true' ) ;
1532+ } else if ( authCompleted ) {
1533+ // Successful auth clears any prior decline so pre-auth resumes on future connections.
1534+ sessionStorage . removeItem ( 'oauth_pre_auth_declined' ) ;
1535+ }
1536+ return ;
1537+ }
15181538 if ( ! selectedConversation || selectedConversation . id !== pendingConversationId ) return ;
15191539
15201540 sessionStorage . removeItem ( 'oauth_pending_message' ) ;
15211541 sessionStorage . removeItem ( 'oauth_pending_conversation_id' ) ;
15221542
1543+ // Successful mid-workflow auth clears any pre-auth decline flag.
1544+ if ( authCompleted ) {
1545+ sessionStorage . removeItem ( 'oauth_pre_auth_declined' ) ;
1546+ }
1547+
15231548 // If the user pressed back without completing OAuth, show a cancellation message.
15241549 if ( ! authCompleted ) {
15251550 const conversation = selectedConversationRef . current ;
0 commit comments