11import { useEffect } from "react" ;
22import { SESSION_KEYS } from "../lib/constants" ;
3- import { useToast } from "@/hooks/use-toast.ts" ;
43import {
54 generateOAuthErrorDescription ,
65 parseOAuthCallbackParams ,
76} from "@/utils/oauthUtils.ts" ;
87
98interface OAuthCallbackProps {
10- onConnect : ( serverUrl : string , authorizationCode ?: string ) => void ;
9+ onConnect : ( {
10+ authorizationCode,
11+ errorMsg,
12+ } : {
13+ authorizationCode ?: string ;
14+ errorMsg ?: string ;
15+ } ) => void ;
1116}
1217
1318const OAuthDebugCallback = ( { onConnect } : OAuthCallbackProps ) => {
14- const { toast } = useToast ( ) ;
15-
1619 useEffect ( ( ) => {
1720 let isProcessed = false ;
1821
@@ -23,16 +26,11 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
2326 }
2427 isProcessed = true ;
2528
26- const notifyError = ( description : string ) =>
27- void toast ( {
28- title : "OAuth Authorization Error" ,
29- description,
30- variant : "destructive" ,
31- } ) ;
32-
3329 const params = parseOAuthCallbackParams ( window . location . search ) ;
3430 if ( ! params . successful ) {
35- return notifyError ( generateOAuthErrorDescription ( params ) ) ;
31+ const errorMsg = generateOAuthErrorDescription ( params ) ;
32+ onConnect ( { errorMsg } ) ;
33+ return ;
3634 }
3735
3836 const serverUrl = sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ;
@@ -47,20 +45,13 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
4745 }
4846
4947 if ( ! params . code ) {
50- return notifyError ( "Missing authorization code" ) ;
48+ onConnect ( { errorMsg : "Missing authorization code" } ) ;
49+ return ;
5150 }
5251
5352 // Instead of storing in sessionStorage, pass the code directly
5453 // to the auth state manager through onConnect
55- onConnect ( serverUrl , params . code ) ;
56-
57- // Show success message
58- toast ( {
59- title : "Success" ,
60- description :
61- "Authorization code received. Returning to the Auth Debugger." ,
62- variant : "default" ,
63- } ) ;
54+ onConnect ( { authorizationCode : params . code } ) ;
6455 } ;
6556
6657 handleCallback ( ) . finally ( ( ) => {
@@ -74,7 +65,7 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
7465 return ( ) => {
7566 isProcessed = true ;
7667 } ;
77- } , [ toast , onConnect ] ) ;
68+ } , [ onConnect ] ) ;
7869
7970 const callbackParams = parseOAuthCallbackParams ( window . location . search ) ;
8071
0 commit comments