mirror of
https://github.com/rjNemo/MERN_sample_app
synced 2026-06-06 08:46: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
|
||||
}) => {
|
||||
const firebase = useFirebase();
|
||||
|
||||
let render;
|
||||
useEffect(() => {
|
||||
firebase.auth.onAuthStateChanged((authUser) => {
|
||||
if (!condition(authUser)) {
|
||||
history.push(ROUTES.SIGN_IN);
|
||||
} else {
|
||||
render = condition(authUser)
|
||||
? (props) => <Component {...props} />
|
||||
: null;
|
||||
}
|
||||
});
|
||||
}, [firebase.auth, condition, history]);
|
||||
|
||||
const render = (props) => <Component {...props} />;
|
||||
return <Route path={path} render={render} {...rest} />;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue