-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 914 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React,{useEffect} from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import registerServiceWorker from './registerServiceWorker';
import {BrowserRouter as Router,Switch,Route,withRouter} from 'react-router-dom';
import {Register, Login} from './components/Auth';
import 'semantic-ui-css/semantic.min.css';
import firebase from './firebase';
const Root = ({history}) => {
useEffect(()=>{
firebase.auth().onAuthStateChanged(user =>{
if(user){
history.push('/');
}
})
},[]);
return (
<Switch>
<Route exact path="/" component={App} />
<Route path="/register" component={Register} />
<Route path="/login" component={Login} />
</Switch>
);
};
const RootwithAuth = withRouter(Root);
ReactDOM.render(<Router><RootwithAuth /></Router>, document.getElementById('root'));
registerServiceWorker();