added error message

main
alex 2023-04-20 17:03:40 +02:00
parent 5b6fb4eb3e
commit a99df8060e
1 changed files with 17 additions and 5 deletions

View File

@ -1,16 +1,17 @@
import { LockOutlined, LoginOutlined, UserOutlined } from "@ant-design/icons"; import { LockOutlined, LoginOutlined, UserOutlined } from "@ant-design/icons";
import { Button, Form, Input, Modal } from "antd"; import { Button, Form, Input, Modal, notification } from "antd";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import config from "../../constants"; import { Constants } from "../../constants";
import { useState } from "react"; import { useState } from "react";
import { Buffer } from "buffer"; import { Buffer } from "buffer";
export default function Login({ setUserSession }) { export default function Login({ setUserSession }) {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [api, contextHolder] = notification.useNotification();
const handleSubmit = () => { const handleSubmit = () => {
fetch(config.API_ADDRESS + "/user/auth/login", { fetch(Constants.API_ADDRESS + "/user/auth/login", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
@ -25,12 +26,23 @@ export default function Login({ setUserSession }) {
return Promise.reject(res.status); return Promise.reject(res.status);
}) })
.then((data) => setUserSession(data.Session)) .then((data) => {
.catch(console.error); setUserSession(data.Session);
window.location.href = "/";
})
.catch((err) => {
console.error(err);
api["error"]({
message: "Login Failed!",
description: "Please check your username and password!",
});
});
}; };
return ( return (
<> <>
{contextHolder}
<Modal <Modal
title="Login" title="Login"
open={true} open={true}