File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,14 @@ import Homepage from './Homepage';
55import PageRegister from './PageRegister' ;
66
77import { Switch , Route } from 'react-router-dom' ;
8+ import { connect } from 'react-redux' ;
9+ import { isLoaded } from 'react-redux-firebase' ;
10+
11+ const App = props => {
12+ if ( ! isLoaded ( props . auth , props . profile ) ) {
13+ return < div > Authentication loading...</ div > ;
14+ }
815
9- const App = ( ) => {
1016 return (
1117 < Switch >
1218 < Route exact path = "/" >
@@ -28,4 +34,8 @@ const App = () => {
2834 ) ;
2935} ;
3036
31- export default App ;
37+ const mapStateToProps = state => {
38+ return { auth : state . firebase . auth , profile : state . firebase . profile } ;
39+ } ;
40+
41+ export default connect ( mapStateToProps ) ( App ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { firebaseConnect } from 'react-redux-firebase' ;
3+ import { connect } from 'react-redux' ;
4+ import { compose } from 'redux' ;
5+ import { Redirect } from 'react-router-dom' ;
36
47class PageRegister extends React . Component {
58 constructor ( props ) {
@@ -27,6 +30,10 @@ class PageRegister extends React.Component {
2730 } ;
2831
2932 render ( ) {
33+ if ( this . props . isLoggedIn ) {
34+ return < Redirect to = "/" /> ;
35+ }
36+
3037 return (
3138 < div >
3239 < h2 > Register</ h2 >
@@ -54,4 +61,11 @@ class PageRegister extends React.Component {
5461 }
5562}
5663
57- export default firebaseConnect ( ) ( PageRegister ) ;
64+ const mapStateToProps = state => {
65+ return { isLoggedIn : state . firebase . auth . uid } ;
66+ } ;
67+
68+ export default compose (
69+ firebaseConnect ( ) ,
70+ connect ( mapStateToProps ) ,
71+ ) ( PageRegister ) ;
You can’t perform that action at this time.
0 commit comments