diff --git a/AceJobAgency.client/src/App.tsx b/AceJobAgency.client/src/App.tsx
index b33c6bf..eca7094 100644
--- a/AceJobAgency.client/src/App.tsx
+++ b/AceJobAgency.client/src/App.tsx
@@ -2,6 +2,8 @@ import { Route, Routes } from "react-router-dom";
import DefaultLayout from "./layouts/DefaultLayout";
import HomePage from "./pages/HomePage";
import ErrorPage from "./pages/ErrorPage";
+import { getAccessToken } from "./http";
+import MemberPage from "./pages/MemberPage";
export default function App() {
return (
@@ -9,7 +11,10 @@ export default function App() {
}>
- } />
+ : }
+ />
} />
diff --git a/AceJobAgency.client/src/components/LoginView.tsx b/AceJobAgency.client/src/components/LoginView.tsx
index a5a41fc..4860cd9 100644
--- a/AceJobAgency.client/src/components/LoginView.tsx
+++ b/AceJobAgency.client/src/components/LoginView.tsx
@@ -1,7 +1,46 @@
import { Input, Checkbox, Button, Link } from "@heroui/react";
import { IconMail, IconLock } from "@tabler/icons-react";
+import { useState } from "react";
+import { toast } from "react-toastify";
+import http, { login } from "../http";
export default function LoginView({ onSignup }: { onSignup: () => void }) {
+ const [email, setEmail] = useState("");
+ const [password, setPassword] = useState("");
+
+ const validateFields = () => {
+ if (!email || !password) {
+ toast.error("Both email and password are required.");
+ return false;
+ }
+ return true;
+ };
+
+ const handleLogin = async () => {
+ if (!validateFields()) return;
+
+ const loginRequest = {
+ email,
+ password,
+ };
+
+ try {
+ const response = await http.post("/User/login", loginRequest);
+
+ if (response.status !== 200) {
+ throw new Error("Login failed");
+ }
+
+ const { token } = response.data;
+ login(token);
+ } catch (error) {
+ toast.error(
+ (error as any).response?.data ||
+ "Something went wrong! Please try again."
+ );
+ }
+ };
+
return (
@@ -11,8 +50,20 @@ export default function LoginView({ onSignup }: { onSignup: () => void }) {
- } label="Email" />
- } label="Password" type="password" />
+ }
+ label="Email"
+ type="email"
+ value={email}
+ onValueChange={setEmail}
+ />
+ }
+ label="Password"
+ type="password"
+ value={password}
+ onValueChange={setPassword}
+ />
void }) {
-