mirror of
https://github.com/rjNemo/MERN_sample_app
synced 2026-06-06 08:46:39 +00:00
pages don't render if condition not met
This commit is contained in:
parent
c8b29a5e22
commit
75361d6f0a
2 changed files with 8 additions and 4 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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} />;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue