fixed issue with double login close #53 #57
@@ -49,6 +49,44 @@ class ProtectedRoute extends Component {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class CheckRoute extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { auth: null };
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
const url = "/simcompanies/API/testlogin";
|
||||
const response = await fetch(url);
|
||||
if (response.status == "200") {
|
||||
this.setState({
|
||||
auth: true
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
auth: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { component: Component, ...props } = this.props;
|
||||
return (
|
||||
this.state.auth === null ?
|
||||
"Loading..." :
|
||||
<Route
|
||||
{...props}
|
||||
render={props => (
|
||||
this.state.auth ?
|
||||
<Redirect to='/' /> :
|
||||
<Component {...props} />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
|
||||
render() {
|
||||
@@ -71,8 +109,8 @@ class App extends Component {
|
||||
<ThemeProvider theme={theme}>
|
||||
<BrowserRouter basename="/simcompanies">
|
||||
<Switch>
|
||||
<Route exact path="/login" component={Login} />
|
||||
<Route exact path="/login/createuser" component={CreateAccount} />
|
||||
<CheckRoute exact path="/login" component={Login} />
|
||||
<CheckRoute exact path="/login/createuser" component={CreateAccount} />
|
||||
<ProtectedRoute path="/*" component={Navbar} />
|
||||
</Switch>
|
||||
</BrowserRouter>
|
||||
|
||||
Reference in New Issue
Block a user