From a99df8060e59e9eab291753e7533756446a14667 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 20 Apr 2023 17:03:40 +0200 Subject: [PATCH] added error message --- src/Pages/Login/index.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Pages/Login/index.js b/src/Pages/Login/index.js index dc34cd6..7501605 100644 --- a/src/Pages/Login/index.js +++ b/src/Pages/Login/index.js @@ -1,16 +1,17 @@ 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 config from "../../constants"; +import { Constants } from "../../constants"; import { useState } from "react"; import { Buffer } from "buffer"; export default function Login({ setUserSession }) { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + const [api, contextHolder] = notification.useNotification(); const handleSubmit = () => { - fetch(config.API_ADDRESS + "/user/auth/login", { + fetch(Constants.API_ADDRESS + "/user/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -25,12 +26,23 @@ export default function Login({ setUserSession }) { return Promise.reject(res.status); }) - .then((data) => setUserSession(data.Session)) - .catch(console.error); + .then((data) => { + setUserSession(data.Session); + window.location.href = "/"; + }) + .catch((err) => { + console.error(err); + + api["error"]({ + message: "Login Failed!", + description: "Please check your username and password!", + }); + }); }; return ( <> + {contextHolder}