@@ -20,48 +20,44 @@ export interface DeepLinkHandler {
2020
2121export function useDeepLinkManager ( ) {
2222 const addError = useAppStore ( ( state ) => state . addError ) ;
23- const ssoRequestID = useAppStore ( ( state ) => state . ssoRequestID ) ;
24- const cloudSelectService = useConnectStore (
25- ( state ) => state . cloudSelectService
26- ) ;
2723 const { t } = useTranslation ( ) ;
2824
2925 // handle oauth callback
30- const handleOAuthCallback = useCallback (
31- async ( url : URL ) => {
32- try {
33- const reqId = url . searchParams . get ( "request_id" ) ;
34- const code = url . searchParams . get ( "code" ) ;
35-
36- if ( reqId !== ssoRequestID ) {
37- console . log ( "Request ID not matched, skip" ) ;
38- addError ( "Request ID not matched, skip" ) ;
39- return ;
40- }
26+ const handleOAuthCallback = useCallback ( async ( url : URL ) => {
27+ try {
28+ const reqId = url . searchParams . get ( "request_id" ) ;
29+ const code = url . searchParams . get ( "code" ) ;
4130
42- const serverId = cloudSelectService ?. id ;
43- if ( ! code || ! serverId ) {
44- addError ( "No authorization code received" ) ;
45- return ;
46- }
31+ const { ssoRequestID } = useAppStore . getState ( ) ;
32+ const { cloudSelectService } = useConnectStore . getState ( ) ;
4733
48- console . log ( "Handling OAuth callback:" , { code, serverId } ) ;
49- await platformAdapter . commands ( "handle_sso_callback" , {
50- serverId : serverId ,
51- requestId : ssoRequestID ,
52- code : code ,
53- } ) ;
34+ if ( reqId !== ssoRequestID ) {
35+ console . log ( "Request ID not matched, skip" ) ;
36+ addError ( "Request ID not matched, skip" ) ;
37+ return ;
38+ }
5439
55- // trigger oauth success event
56- platformAdapter . emitEvent ( "oauth_success" , { serverId } ) ;
57- getCurrentWindow ( ) . setFocus ( ) ;
58- } catch ( err ) {
59- console . error ( "Failed to parse OAuth callback URL:" , err ) ;
60- addError ( "Invalid OAuth callback URL format: " + err ) ;
40+ const serverId = cloudSelectService ?. id ;
41+ if ( ! code || ! serverId ) {
42+ addError ( "No authorization code received" ) ;
43+ return ;
6144 }
62- } ,
63- [ ssoRequestID , cloudSelectService , addError ]
64- ) ;
45+
46+ console . log ( "Handling OAuth callback:" , { code, serverId } ) ;
47+ await platformAdapter . commands ( "handle_sso_callback" , {
48+ serverId : serverId ,
49+ requestId : ssoRequestID ,
50+ code : code ,
51+ } ) ;
52+
53+ // trigger oauth success event
54+ platformAdapter . emitEvent ( "oauth_success" , { serverId } ) ;
55+ getCurrentWindow ( ) . setFocus ( ) ;
56+ } catch ( err ) {
57+ console . error ( "Failed to parse OAuth callback URL:" , err ) ;
58+ addError ( "Invalid OAuth callback URL format: " + err ) ;
59+ }
60+ } , [ ] ) ;
6561
6662 // handle install extension from store
6763 const handleInstallExtension = useCallback ( async ( url : URL ) => {
0 commit comments