From e1b72d4187a2863d37e7fb067c23e585ace10f1d Mon Sep 17 00:00:00 2001
From: Michael Utama <michaelu670@gmail.com>
Date: Thu, 16 Nov 2023 16:52:28 +0700
Subject: [PATCH] chore: redo missing commit

---
 src/pages/Login/Login.tsx | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/src/pages/Login/Login.tsx b/src/pages/Login/Login.tsx
index d9f5c40..5e137f3 100644
--- a/src/pages/Login/Login.tsx
+++ b/src/pages/Login/Login.tsx
@@ -9,6 +9,7 @@ import { REST_BASE_URL } from "../../constant/constants";
 
 import FormGroup from "@/components/AuthenticationForm/FormGroup";
 import FormButton from "@/components/AuthenticationForm/FormButton";
+import { login } from "@/utils/login";
 
 const Login = () => {
   const [username, setUsername] = useState<string>("");
@@ -30,24 +31,11 @@ const Login = () => {
   const onLogin = async (e: React.SyntheticEvent) => {
     e.preventDefault();
 
-    // Build JSON data to be sent
-    const requestBody = {
-      username,
-      password,
-    };
+    const response = login(username, password);
 
-    // Send POST request
-    const response = await fetch(`${REST_BASE_URL}/user/token`, {
-      method: "POST",
-      headers: {
-        "Content-Type": "application/json",
-      },
-      body: JSON.stringify(requestBody),
-    });
+    const data = await response;
 
-    const data = await response.json();
-
-    if (!response.ok) {
+    if (!data.ok) {
       toast.error(data.message, {
         position: "top-center",
         autoClose: 1500,
@@ -59,7 +47,6 @@ const Login = () => {
         theme: "light",
       });
     } else {
-      localStorage.setItem("token", `Bearer ${data.token}`);
       navigate("/");
     }
   };
-- 
GitLab