11import React from 'react' ;
2- import { Switch , Route } from 'react-router-dom' ;
2+ import { Switch , Route , withRouter } from 'react-router-dom' ;
33import Header from './components/Header.jsx' ;
44import Sidebar from './components/Sidebar.jsx' ;
55import Footer from './components/Footer.jsx' ;
6- import HiddenSidebar from './components/HiddenSidebar.jsx' ;
76import Socket from '../socket.js' ;
87import Index from "./components/Index" ;
98import UsersContent from "./components/UsersContent" ;
@@ -38,14 +37,6 @@ class App extends React.Component {
3837
3938 componentDidMount ( ) {
4039 this . checkLogin ( ) ;
41- // Wait 1 second before redirecting to login page
42- setTimeout ( ( ) => {
43- if ( ! this . state . loggedIn ) {
44- browserHistory . push ( "/login" ) ;
45- }
46- } , 1000 ) ;
47- this . connectWebSocket ( ) ;
48- this . getFactorioVersion ( ) ; //Init serverStatus, so i know, which factorio-version is installed
4940 }
5041
5142 connectWebSocket ( ) {
@@ -63,14 +54,23 @@ class App extends React.Component {
6354 checkLogin ( ) {
6455 $ . ajax ( {
6556 url : "/api/user/status" ,
57+ type : "GET" ,
6658 dataType : "json" ,
6759 success : ( data ) => {
6860 if ( data . success === true ) {
6961 this . setState ( {
7062 loggedIn : true ,
7163 username : data . data . Username
7264 } ) ;
65+
66+ this . connectWebSocket ( ) ;
67+ this . getFactorioVersion ( ) ; //Init serverStatus, so i know, which factorio-version is installed
68+ } else {
69+ this . props . history . push ( "/login" ) ;
7370 }
71+ } ,
72+ error : ( ) => {
73+ this . props . history . push ( "/login" ) ;
7474 }
7575 } )
7676 }
@@ -128,6 +128,7 @@ class App extends React.Component {
128128 url : "/api/server/facVersion" ,
129129 // dataType: "json",
130130 success : ( data ) => {
131+ console . log ( data ) ;
131132 this . setState ( {
132133 factorioVersion : data . data . base_mod_version
133134 } ) ;
@@ -180,17 +181,10 @@ class App extends React.Component {
180181 < Route path = "/saves" render = { ( props ) => { return < SavesContent { ...props } { ...appProps } /> } } />
181182 < Route path = "/config" render = { ( props ) => { return < ConfigContent { ...props } { ...appProps } /> } } />
182183 < Route path = "/console" render = { ( props ) => { return < ConsoleContent { ...props } { ...appProps } /> } } />
183- < Route exakt path = "/" render = { ( props ) => { return < Index { ...props } { ...appProps } /> } } />
184+ < Route exact path = "/" render = { ( props ) => { return < Index { ...props } { ...appProps } /> } } />
184185 </ Switch >
185186
186187 < Footer />
187-
188- < HiddenSidebar
189- serverStatus = { this . state . serverStatus }
190- username = { this . state . username }
191- loggedIn = { this . state . loggedIn }
192- checkLogin = { this . checkLogin }
193- />
194188 </ div >
195189 } else {
196190 resp = < div > < p > Not Logged in</ p > </ div > ;
@@ -200,4 +194,4 @@ class App extends React.Component {
200194 }
201195}
202196
203- export default App
197+ export default withRouter ( App ) ;
0 commit comments