mirror of
https://github.com/rjNemo/MERN_sample_app
synced 2026-06-12 11:36: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 { 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>
|
||||||
|
|
|
||||||
|
|
@ -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} />;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue