pages don't render if condition not met

This commit is contained in:
Ruidy Nemausat 2020-04-24 12:01:34 +02:00
parent c8b29a5e22
commit 75361d6f0a
2 changed files with 8 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import React from "react";
import { Container } from "reactstrap";
import PasswordChangeForm from "../../components/PasswordChangeForm";
import PasswordForgetForm from "../../components/PasswordForgetForm";
import { useFirebase } from "../../services/auth";
const styles = {
root: {
@ -11,6 +12,8 @@ const styles = {
};
const AccountPage = () => {
const auth = useFirebase();
return (
<Container style={styles.root}>
<h1>Account</h1>

View file

@ -11,18 +11,19 @@ const PrivateRoute = ({
...rest
}) => {
const firebase = useFirebase();
let render;
let render = null;
useEffect(() => {
firebase.auth.onAuthStateChanged((authUser) => {
if (!condition(authUser)) {
history.push(ROUTES.SIGN_IN);
} else {
render = condition(authUser)
? (props) => <Component {...props} />
: null;
// render = condition(authUser)
// ? (props) => <Component {...props} />
// : null;
}
});
}, [firebase.auth, condition, history]);
render = (props) => <Component {...props} />;
return <Route path={path} render={render} {...rest} />;
};