mirror of
https://github.com/rjNemo/MERN_sample_app
synced 2026-06-11 19:16:39 +00:00
adds private route component and updates router
This commit is contained in:
parent
0262465acc
commit
c8b29a5e22
1 changed files with 5 additions and 2 deletions
|
|
@ -11,16 +11,19 @@ const PrivateRoute = ({
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const firebase = useFirebase();
|
const firebase = useFirebase();
|
||||||
|
let render;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
firebase.auth.onAuthStateChanged((authUser) => {
|
firebase.auth.onAuthStateChanged((authUser) => {
|
||||||
if (!condition(authUser)) {
|
if (!condition(authUser)) {
|
||||||
history.push(ROUTES.SIGN_IN);
|
history.push(ROUTES.SIGN_IN);
|
||||||
|
} else {
|
||||||
|
render = condition(authUser)
|
||||||
|
? (props) => <Component {...props} />
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [firebase.auth, condition, history]);
|
}, [firebase.auth, condition, history]);
|
||||||
|
|
||||||
const render = (props) => <Component {...props} />;
|
|
||||||
return <Route path={path} render={render} {...rest} />;
|
return <Route path={path} render={render} {...rest} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue