@@ -3,19 +3,20 @@ import PropTypes from "prop-types";
33import { Route , withRouter } from "react-router-dom" ;
44import { useAuth0 } from "../react-auth0-spa" ;
55
6- const PrivateRoute = ( { component : Component , path, location , ...rest } ) => {
7- const { isAuthenticated, loginWithRedirect } = useAuth0 ( ) ;
6+ const PrivateRoute = ( { component : Component , path, ...rest } ) => {
7+ const { loading , isAuthenticated, loginWithRedirect } = useAuth0 ( ) ;
88
99 useEffect ( ( ) => {
10+ if ( loading || isAuthenticated ) {
11+ return ;
12+ }
1013 const fn = async ( ) => {
11- if ( ! isAuthenticated ) {
12- await loginWithRedirect ( {
13- appState : { targetUrl : location . pathname }
14- } ) ;
15- }
14+ await loginWithRedirect ( {
15+ appState : { targetUrl : path }
16+ } ) ;
1617 } ;
1718 fn ( ) ;
18- } , [ isAuthenticated , loginWithRedirect , path , location ] ) ;
19+ } , [ loading , isAuthenticated , loginWithRedirect , path ] ) ;
1920
2021 const render = props =>
2122 isAuthenticated === true ? < Component { ...props } /> : null ;
@@ -26,9 +27,6 @@ const PrivateRoute = ({ component: Component, path, location, ...rest }) => {
2627PrivateRoute . propTypes = {
2728 component : PropTypes . oneOfType ( [ PropTypes . element , PropTypes . func ] )
2829 . isRequired ,
29- location : PropTypes . shape ( {
30- pathname : PropTypes . string . isRequired
31- } ) . isRequired ,
3230 path : PropTypes . oneOfType ( [
3331 PropTypes . string ,
3432 PropTypes . arrayOf ( PropTypes . string )
0 commit comments