diff --git a/frontend/src/App.js b/frontend/src/App.js index 3ee77e8..fa56e5e 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -11,10 +11,46 @@ import Login from './components/login/login'; import CreateAccount from './components/login/createAccount'; import "./App.css"; +import { Redirect } from "react-router-dom"; +class ProtectedRoute extends Component { + constructor(props) { + super(props); + this.state = { auth: false }; + } + 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 + } + } + } + checkLogin(url) + const { component: Component, ...props } = this.props + + return ( + ( + this.state.authenticated ? + : + + )} + /> + ) + } +} class App extends Component { + render() { const theme = createMuiTheme({ palette: { @@ -29,6 +65,7 @@ class App extends Component { } }) + //change basename in browserrouter if uri changes return ( @@ -36,10 +73,8 @@ class App extends Component { - + - - diff --git a/frontend/src/components/login/createAccount.js b/frontend/src/components/login/createAccount.js index 2950a44..7805472 100644 --- a/frontend/src/components/login/createAccount.js +++ b/frontend/src/components/login/createAccount.js @@ -9,6 +9,7 @@ import Button from '@material-ui/core/Button'; import Logo from "../../img/logo.png"; import TextField from '@material-ui/core/TextField'; import Grid from '@material-ui/core/Grid'; +import { Redirect } from "react-router-dom"; const url = "/simcompanies/API/user/create" @@ -70,6 +71,10 @@ const putCreateAccount = async (url, data) => { referrerPolicy: 'no-referrer', body: JSON.stringify(data) }); + + if (response.status == "200") { + return + } } export default function CreateAccount() { diff --git a/frontend/src/components/login/login.js b/frontend/src/components/login/login.js index e0ab347..b91a897 100644 --- a/frontend/src/components/login/login.js +++ b/frontend/src/components/login/login.js @@ -10,6 +10,7 @@ import Logo from "../../img/logo.png"; import TextField from '@material-ui/core/TextField'; import Grid from '@material-ui/core/Grid'; import Link1 from '@material-ui/core/Link'; +import { Redirect } from "react-router-dom"; const url = "/simcompanies/API/user/login" const useStyles = makeStyles(theme => ({ @@ -70,18 +71,14 @@ const postLogin = async (url, data) => { referrerPolicy: 'no-referrer', body: JSON.stringify(data) }); -} - -const checkLogin = async (url) => { - const response = await fetch(url); if (response.status == "200") { - return true - } else { - return false + return } } + + export default function Login() { const classes = useStyles();