@@ -15,6 +15,7 @@ export const OAuthAuthorizationStatusModal: FC = () => {
1515 const [ authCodeUrlStr , setAuthCodeUrlStr ] = useState < string | undefined > ( ) ;
1616 const [ submitting , setSubmitting ] = useState < boolean > ( false ) ;
1717 const { submit : redirectToDefaultBrowserSubmit } = useDefaultBrowserRedirectActionFetcher ( ) ;
18+ const [ error , setError ] = useState < string | null > ( null ) ;
1819
1920 useEffect ( ( ) => {
2021 const unsubscribe = window . main . on ( 'show-oauth-authorization-modal' , ( _ , authCodeUrlStr : string ) => {
@@ -65,6 +66,7 @@ export const OAuthAuthorizationStatusModal: FC = () => {
6566 } else if ( status === 'getting_code' ) {
6667 modalRef . current ?. show ( ) ;
6768 setSubmitting ( false ) ;
69+ setError ( null ) ;
6870 }
6971 } , [ status ] ) ;
7072
@@ -84,7 +86,7 @@ export const OAuthAuthorizationStatusModal: FC = () => {
8486 { status === 'getting_code' && (
8587 < >
8688 < p className = "text-[rgba(var(--color-font-rgb),0.8))] text-start" >
87- See your browser to finish authorization, if the browser didn’ t open automatically, copy and paste this
89+ See your browser to finish authorization, if the browser didn' t open automatically, copy and paste this
8890 URL into your browser to authorize.
8991 </ p >
9092 < div className = "form-control form-control--outlined no-pad-top flex" >
@@ -110,29 +112,36 @@ export const OAuthAuthorizationStatusModal: FC = () => {
110112 </ p >
111113 < form
112114 onSubmit = { e => {
113- e . preventDefault ( ) ;
114- const form = e . currentTarget ;
115- const data = new FormData ( form ) ;
115+ try {
116+ e . preventDefault ( ) ;
117+ const form = e . currentTarget ;
118+ const data = new FormData ( form ) ;
116119
117- const url = data . get ( 'url' ) ;
118- invariant ( typeof url === 'string' , 'Expected code to be a string' ) ;
119- if ( url . length === 0 ) {
120- return ;
121- }
122- setSubmitting ( true ) ;
123- const parsedUrl = new URL ( url ) ;
124- const params = Object . fromEntries ( parsedUrl . searchParams ) ;
125- const { encryptedUrl : encryptedRedirectUrl , encryptedKey, iv } = params ;
126- if ( encryptedRedirectUrl && encryptedKey && iv ) {
120+ const url = data . get ( 'url' ) ;
121+ invariant ( typeof url === 'string' , 'Expected code to be a string' ) ;
122+ if ( url . length === 0 ) {
123+ return ;
124+ }
125+ setError ( null ) ;
126+ setSubmitting ( true ) ;
127+ const parsedUrl = new URL ( url ) ;
128+ const params = Object . fromEntries ( parsedUrl . searchParams ) ;
129+ const { encryptedUrl : encryptedRedirectUrl , encryptedKey, iv } = params ;
130+ if ( encryptedRedirectUrl && encryptedKey && iv ) {
131+ return redirectToDefaultBrowserSubmit ( {
132+ encryptedRedirectUrl,
133+ encryptedKey,
134+ iv,
135+ } ) ;
136+ }
127137 return redirectToDefaultBrowserSubmit ( {
128- encryptedRedirectUrl,
129- encryptedKey,
130- iv,
138+ redirectUrl : url ,
131139 } ) ;
140+ } catch ( error ) {
141+ setError ( error instanceof Error ? error . message : String ( error ) ) ;
142+ setSubmitting ( false ) ;
143+ return ;
132144 }
133- return redirectToDefaultBrowserSubmit ( {
134- redirectUrl : url ,
135- } ) ;
136145 } }
137146 >
138147 < div className = "form-control form-control--outlined no-pad-top" style = { { display : 'flex' } } >
@@ -151,6 +160,7 @@ export const OAuthAuthorizationStatusModal: FC = () => {
151160 Proceed
152161 </ button >
153162 </ div >
163+ { error && < p className = "text-danger" > Error: { error } </ p > }
154164 </ form >
155165 </ >
156166 ) }
0 commit comments