fixed login redirect

This commit is contained in:
2020-04-25 02:22:52 +02:00
parent 7e4e39816a
commit 55e693b38d

View File

@@ -12,7 +12,7 @@ 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 => ({
card: {
backgroundColor: "#0B1929",
@@ -59,7 +59,16 @@ const CssTextField = withStyles({
},
})(TextField);
const postLogin = async (url, data) => {
export default function Login() {
const classes = useStyles();
const url = "/simcompanies/API/user/login"
const [username, setUsername] = React.useState("");
const [password, setPassword] = React.useState("");
const [login, setLogin] = React.useState(true);
const postLogin = async (url, data) => {
const response = await fetch(url, {
method: 'POST',
mode: 'cors',
@@ -73,17 +82,9 @@ const postLogin = async (url, data) => {
});
if (response.status == "200") {
return <Redirect to={"/"} />
setLogin(false)
}
}
}
export default function Login() {
const classes = useStyles();
const [username, setUsername] = React.useState("");
const [password, setPassword] = React.useState("");
const handleClick = (e) => {
@@ -100,8 +101,12 @@ export default function Login() {
const handleChangePW = (e) => {
setPassword(e.target.value)
}
return (
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
login === true ?
< Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
<Card className={classes.card} raised>
<CardContent>
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
@@ -164,7 +169,7 @@ export default function Login() {
</form>
</CardContent>
</Card>
</Box >
</Box > : <Redirect to='/' />
)
}