diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index 78b6d25..4b34852 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -8,12 +8,12 @@ import { export type User = { name: string; - email: string; + pass: string; }; export type AuthContextProps = { getUser: () => User | null; - login: () => void; + login: (arg0: string, arg1: string) => void; logout: () => void; isLoggedIn: () => boolean; }; @@ -30,14 +30,14 @@ export function useAuth() { } export function AuthProvider({ children }: { children: ReactElement }) { - const [user, setUser] = useState(null); + const [user, setUser] = useState(null); - const login = useCallback(() => { + const login = useCallback((name: string, pass: string) => { setUser({ - name: 'John Doe', - email: '', + name: name, + pass: pass, }); - }, []); + }, [setUser]); const logout = useCallback(() => { setUser(null); diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 237e8c7..93e42d3 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -20,7 +20,7 @@ const Home: React.FC = () => { const auth = useAuth(); const handleLogin = () => { - auth.login(); + navigate('/login'); }; const handleLogout = () => { diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index bf760ac..72a45d2 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,15 +1,17 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import Button from '../library/button'; import Input from '../library/input'; import Navbar from '../Navbar'; import { Link } from 'react-router-dom'; +import { useAuth } from '../contexts/AuthContext'; import '../index.css'; const Login: React.FC = () => { - const [email, setEmail] = useState(''); + const [name, setName] = useState(''); const [password, setPassword] = useState(''); const [isLoggedIn, setIsLoggedIn] = useState(false); const [username, setUsername] = useState(''); + const auth = useAuth(); const handleLogin = () => { setUsername('Username_7'); @@ -21,89 +23,99 @@ const Login: React.FC = () => { setIsLoggedIn(false); }; - const handleEmailChange = (event: React.ChangeEvent) => { - setEmail(event.target.value); + const handleNameChange = (event: React.ChangeEvent) => { + setName(event.target.value); }; const handlePasswordChange = (event: React.ChangeEvent) => { setPassword(event.target.value); }; + const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); console.log('Form submitted'); - // Handle form submission logic here + auth.login(name, password) }; + useEffect(() => { + const user = auth.getUser(); + console.log(user); + setIsLoggedIn(auth.isLoggedIn()); + console.log(isLoggedIn); + }, [auth, auth.getUser()]); + return ( -
- -
-
-
-
-
-
-
-
-
- -
-
- + <> +
+ +
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+
-
-
+
- -
+ + ); };