Skip to content

Commit 950d14c

Browse files
authored
DT-1170 - Update App.jsx to handle auth library not yet loaded (#1741)
1 parent 0dd6abc commit 950d14c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/containers/App.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ export function App(props) {
162162
const auth = useAuth();
163163
// This effect clause is needed to handle when the auth library loads the token on page refresh
164164
useEffect(() => {
165-
if (auth.isAuthenticated && !auth.isLoading && !user.isAuthenticated && !auth.activeNavigator) {
165+
if (
166+
auth &&
167+
auth.isAuthenticated &&
168+
!auth.isLoading &&
169+
!user.isAuthenticated &&
170+
!auth.activeNavigator
171+
) {
166172
dispatch(logInSuccess(auth.user));
167173
dispatch(getUserStatus());
168174
auth.events.addUserLoaded((u) => dispatch(userRefresh(u)));
@@ -186,7 +192,7 @@ export function App(props) {
186192
}
187193
};
188194

189-
const loggingIn = status.tdrOperational && configuration.configObject.clientId && auth.isLoading;
195+
const loggingIn = status.tdrOperational && configuration.configObject.clientId && auth?.isLoading;
190196

191197
return (
192198
<div className={classes.root}>
@@ -243,7 +249,7 @@ export function App(props) {
243249
</AppBar>
244250
<div className={clsx(classes.content, { [classes.loggingIn]: loggingIn })}>
245251
{!status.tdrOperational && <ServerErrorView />}
246-
{status.tdrOperational && configuration.configObject.clientId && !auth.isLoading && (
252+
{status.tdrOperational && configuration.configObject.clientId && !auth?.isLoading && (
247253
<Switch>
248254
<Route path="/redirect-from-oauth" exact component={LoadingSpinner} />
249255
<RoutePublic
@@ -268,7 +274,7 @@ export function App(props) {
268274
)}
269275
{!user.isInitiallyLoaded && (
270276
<RoutePrivate
271-
isAuthenticated={auth.isAuthenticated && !auth.isLoading && !user.isTest}
277+
isAuthenticated={auth?.isAuthenticated && !auth?.isLoading && !user.isTest}
272278
path="/"
273279
component={LoadingSpinner}
274280
/>

0 commit comments

Comments
 (0)