diff --git a/src/pages/Login.js b/src/pages/Login.js index 5bb7ddd..0c45fb3 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -1,7 +1,9 @@ -import React from "react"; +import React, { useState } from "react"; +import { Route, Routes, useNavigate } from "react-router"; import '../css/pages/Login.css'; import logoImg from '../img/logo.png'; -import { post } from "../util/Util"; +import { useLoginContext } from "../structures/UserContext"; +import { fetchUser, post } from "../util/Util"; const loginMethods = [ { @@ -10,35 +12,52 @@ const loginMethods = [ } ]; -const Login = () => { - document.body.classList.add('bg-triangles'); + +const CredentialFields = () => { + + const [, setUser] = useLoginContext(); + const [fail, setFail] = useState(false); + const navigate = useNavigate(); + console.log(fail); const loginClick = async () => { const username = document.getElementById('username').value; const password = document.getElementById('password').value; if (!username.length || !password.length) return; - await post('/api/login', {username, password}); + const result = await post('/api/login', { username, password }); + console.log(result); + if (!result.success) { + setFail(true); + return; + } + + if (!result.twoFactor) { + setUser(await fetchUser()); + return navigate('/home'); + } + return navigate('/login/verify'); }; - return