@@ -74,7 +74,6 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
74
74
totpChildren,
75
75
} = props ;
76
76
77
- const [ isComponentLoading , setIsComponentLoading ] = useState < boolean > ( true ) ;
78
77
const [ alert , setAlert ] = useState < AlertType > ( ) ;
79
78
const [ showSelfSignUp , setShowSelfSignUp ] = useState < boolean > ( showSignUp ) ;
80
79
const [ componentBranding , setComponentBranding ] = useState < Branding > ( ) ;
@@ -104,12 +103,13 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
104
103
authorize ( )
105
104
. then ( ( response : AuthApiResponse ) => {
106
105
authContext ?. setAuthResponse ( response ) ;
107
- setIsComponentLoading ( false ) ;
108
106
} )
109
107
. catch ( ( error : Error ) => {
110
108
setAlert ( { alertType : { error : true } , key : keys . common . error } ) ;
111
- setIsComponentLoading ( false ) ;
112
109
throw new AsgardeoUIException ( 'REACT_UI-SIGN_IN-SI-SE01' , 'Authorization failed' , error . stack ) ;
110
+ } )
111
+ . finally ( ( ) => {
112
+ authContext ?. setIsComponentLoading ( false ) ;
113
113
} ) ;
114
114
} , [ ] ) ;
115
115
@@ -125,7 +125,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
125
125
throw new AsgardeoUIException ( 'REACT_UI-SIGN_IN-HA-IV02' , 'Auth response is undefined.' ) ;
126
126
}
127
127
128
- authContext . setIsAuthLoading ( true ) ;
128
+ authContext ? .setIsAuthLoading ( true ) ;
129
129
130
130
const resp : AuthApiResponse = await authenticate ( {
131
131
flowId : authContext ?. authResponse . flowId ,
@@ -135,7 +135,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
135
135
} ,
136
136
} ) . catch ( ( authnError : Error ) => {
137
137
setAlert ( { alertType : { error : true } , key : keys . common . error } ) ;
138
- authContext . setIsAuthLoading ( false ) ;
138
+ authContext ? .setIsAuthLoading ( false ) ;
139
139
throw new AsgardeoUIException ( 'REACT_UI-SIGN_IN-HA-SE03' , 'Authentication failed.' , authnError . stack ) ;
140
140
} ) ;
141
141
@@ -185,7 +185,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
185
185
186
186
await authInstance . requestAccessToken ( resp . authData . code , resp . authData . session_state , state ) ;
187
187
188
- authContext . setAuthentication ( ) ;
188
+ authContext ? .setAuthentication ( ) ;
189
189
} else if ( resp . flowStatus === FlowStatus . FailIncomplete ) {
190
190
authContext ?. setAuthResponse ( {
191
191
...resp ,
@@ -198,7 +198,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
198
198
setShowSelfSignUp ( false ) ;
199
199
}
200
200
201
- authContext . setIsAuthLoading ( false ) ;
201
+ authContext ? .setIsAuthLoading ( false ) ;
202
202
} ;
203
203
204
204
const renderLoginOptions = ( authenticators : Authenticator [ ] ) : ReactElement [ ] => {
@@ -208,7 +208,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
208
208
const displayName : string = authenticator . idp === 'LOCAL' ? authenticator . authenticator : authenticator . idp ;
209
209
LoginOptions . push (
210
210
< LoginOptionsBox
211
- isAuthLoading = { authContext . isAuthLoading }
211
+ isAuthLoading = { authContext ? .isAuthLoading }
212
212
socialName = { authenticator . authenticator }
213
213
displayName = { `${ t ( keys . common . multiple . options . prefix ) } ${ displayName } ` }
214
214
handleOnClick = { ( ) : Promise < void > => handleAuthenticate ( authenticator . authenticatorId ) }
@@ -345,7 +345,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
345
345
/**
346
346
* Renders the circular progress component while the component or text is loading.
347
347
*/
348
- if ( isComponentLoading || isLoading || authContext . isBrandingLoading ) {
348
+ if ( authContext ?. isComponentLoading || isLoading || authContext ? .isBrandingLoading ) {
349
349
return (
350
350
< div className = "Box-circularProgressHolder" >
351
351
< CircularProgress className = "circular-progress" />
@@ -364,14 +364,14 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
364
364
return (
365
365
< ThemeProvider theme = { generateThemeSignIn ( componentBranding ?. preference . theme ) } >
366
366
< UISignIn className = "Box-asgardeoSignIn" >
367
- { showLogo && ! ( isLoading || isComponentLoading ) && (
367
+ { showLogo && ! ( isLoading || authContext ?. isComponentLoading ) && (
368
368
< UISignIn . Image className = "asgardeo-sign-in-logo" src = { imgUrl } />
369
369
) }
370
370
{ authContext ?. authResponse ?. flowStatus !== FlowStatus . SuccessCompleted && ! isAuthenticated && (
371
371
< >
372
372
{ renderSignIn ( ) }
373
373
374
- { showFooter && ! ( isLoading || isComponentLoading ) && (
374
+ { showFooter && ! ( isLoading || authContext ?. isComponentLoading ) && (
375
375
< UISignIn . Footer
376
376
className = "asgardeo-sign-in-footer"
377
377
copyrights = { { children : copyrightText } }
0 commit comments