Merge branch 'login' of https://gitea.oliver.boehlk.io/oliver/simcompanies-dashboard into login
This commit is contained in:
@@ -16,36 +16,36 @@ import { Redirect } from "react-router-dom";
|
||||
class ProtectedRoute extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { auth: false };
|
||||
this.state = { auth: null };
|
||||
}
|
||||
render() {
|
||||
const url = "/simcompanies/API/testlogin"
|
||||
const checkLogin = async (url) => {
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.status == "200") {
|
||||
this.setState = {
|
||||
auth: true
|
||||
}
|
||||
} else {
|
||||
this.setState = {
|
||||
auth: false
|
||||
}
|
||||
}
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
checkLogin(url)
|
||||
const { component: Component, ...props } = this.props
|
||||
|
||||
render() {
|
||||
const { component: Component, ...props } = this.props;
|
||||
return (
|
||||
<Route
|
||||
{...props}
|
||||
render={props => (
|
||||
this.state.authenticated ?
|
||||
<Component {...props} /> :
|
||||
<Redirect to='/login' />
|
||||
)}
|
||||
/>
|
||||
this.state.auth === null ?
|
||||
"Loading..." :
|
||||
<Route
|
||||
{...props}
|
||||
render={props => (
|
||||
this.state.auth ?
|
||||
<Component {...props} /> :
|
||||
<Redirect to='/login' />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user