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

View file

@ -11,18 +11,19 @@ const PrivateRoute = ({
...rest ...rest
}) => { }) => {
const firebase = useFirebase(); const firebase = useFirebase();
let render; let render = null;
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 { } else {
render = condition(authUser) // render = condition(authUser)
? (props) => <Component {...props} /> // ? (props) => <Component {...props} />
: null; // : null;
} }
}); });
}, [firebase.auth, condition, history]); }, [firebase.auth, condition, history]);
render = (props) => <Component {...props} />;
return <Route path={path} render={render} {...rest} />; return <Route path={path} render={render} {...rest} />;
}; };