added error message
parent
5b6fb4eb3e
commit
a99df8060e
|
@ -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}
|
||||
<Modal
|
||||
title="Login"
|
||||
open={true}
|
||||
|
|
Loading…
Reference in New Issue