Skip to content

Commit 4ae64eb

Browse files
Steve Hobbsluisrudge
authored andcommitted
Prevented PrivateRoute from briefly showing page when unauthenticated (#140)
1 parent 31d6d58 commit 4ae64eb

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

01-Login/src/components/PrivateRoute.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const PrivateRoute = ({ component: Component, path, ...rest }) => {
1717
fn();
1818
}, [isAuthenticated, loginWithRedirect, path]);
1919

20-
const render = props => <Component {...props} />;
20+
const render = props =>
21+
isAuthenticated === true ? <Component {...props} /> : null;
2122

2223
return <Route path={path} render={render} {...rest} />;
2324
};

02-Calling-an-API/src/components/PrivateRoute.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const PrivateRoute = ({ component: Component, path, ...rest }) => {
1919

2020
if (!isAuthenticated) return null;
2121

22-
const render = props => <Component {...props} />;
22+
const render = props =>
23+
isAuthenticated === true ? <Component {...props} /> : null;
2324

2425
return <Route path={path} render={render} {...rest} />;
2526
};

0 commit comments

Comments
 (0)