Skip to content

Commit 0362e93

Browse files
fix(react): Add null checks for AuthContext
1 parent 9d577ed commit 0362e93

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

packages/react/src/components/SignIn/SignIn.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
109109
throw new AsgardeoUIException('REACT_UI-SIGN_IN-SI-SE01', 'Authorization failed', error.stack);
110110
})
111111
.finally(() => {
112-
authContext.setIsComponentLoading(false);
112+
authContext?.setIsComponentLoading(false);
113113
});
114114
}, []);
115115

@@ -125,7 +125,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
125125
throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-IV02', 'Auth response is undefined.');
126126
}
127127

128-
authContext.setIsAuthLoading(true);
128+
authContext?.setIsAuthLoading(true);
129129

130130
const resp: AuthApiResponse = await authenticate({
131131
flowId: authContext?.authResponse.flowId,
@@ -135,7 +135,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
135135
},
136136
}).catch((authnError: Error) => {
137137
setAlert({alertType: {error: true}, key: keys.common.error});
138-
authContext.setIsAuthLoading(false);
138+
authContext?.setIsAuthLoading(false);
139139
throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-SE03', 'Authentication failed.', authnError.stack);
140140
});
141141

@@ -185,7 +185,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
185185

186186
await authInstance.requestAccessToken(resp.authData.code, resp.authData.session_state, state);
187187

188-
authContext.setAuthentication();
188+
authContext?.setAuthentication();
189189
} else if (resp.flowStatus === FlowStatus.FailIncomplete) {
190190
authContext?.setAuthResponse({
191191
...resp,
@@ -198,7 +198,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
198198
setShowSelfSignUp(false);
199199
}
200200

201-
authContext.setIsAuthLoading(false);
201+
authContext?.setIsAuthLoading(false);
202202
};
203203

204204
const renderLoginOptions = (authenticators: Authenticator[]): ReactElement[] => {
@@ -208,7 +208,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
208208
const displayName: string = authenticator.idp === 'LOCAL' ? authenticator.authenticator : authenticator.idp;
209209
LoginOptions.push(
210210
<LoginOptionsBox
211-
isAuthLoading={authContext.isAuthLoading}
211+
isAuthLoading={authContext?.isAuthLoading}
212212
socialName={authenticator.authenticator}
213213
displayName={`${t(keys.common.multiple.options.prefix)} ${displayName}`}
214214
handleOnClick={(): Promise<void> => handleAuthenticate(authenticator.authenticatorId)}
@@ -345,7 +345,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
345345
/**
346346
* Renders the circular progress component while the component or text is loading.
347347
*/
348-
if (authContext.isComponentLoading || isLoading || authContext.isBrandingLoading) {
348+
if (authContext?.isComponentLoading || isLoading || authContext?.isBrandingLoading) {
349349
return (
350350
<div className="Box-circularProgressHolder">
351351
<CircularProgress className="circular-progress" />
@@ -364,14 +364,14 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
364364
return (
365365
<ThemeProvider theme={generateThemeSignIn(componentBranding?.preference.theme)}>
366366
<UISignIn className="Box-asgardeoSignIn">
367-
{showLogo && !(isLoading || authContext.isComponentLoading) && (
367+
{showLogo && !(isLoading || authContext?.isComponentLoading) && (
368368
<UISignIn.Image className="asgardeo-sign-in-logo" src={imgUrl} />
369369
)}
370370
{authContext?.authResponse?.flowStatus !== FlowStatus.SuccessCompleted && !isAuthenticated && (
371371
<>
372372
{renderSignIn()}
373373

374-
{showFooter && !(isLoading || authContext.isComponentLoading) && (
374+
{showFooter && !(isLoading || authContext?.isComponentLoading) && (
375375
<UISignIn.Footer
376376
className="asgardeo-sign-in-footer"
377377
copyrights={{children: copyrightText}}

0 commit comments

Comments
 (0)