diff --git a/src/pages/Login.js b/src/pages/Login.js index 675ae60..acc5199 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -19,7 +19,9 @@ const CredentialFields = () => { const [fail, setFail] = useState(false); const navigate = useNavigate(); - const loginClick = async () => { + const loginClick = async (event) => { + + event.preventDefault(); const username = document.getElementById('username').value; const password = document.getElementById('password').value; if (!username.length || !password.length) return; @@ -35,6 +37,7 @@ const CredentialFields = () => { setUser(await fetchUser()); return navigate('/home'); } + return navigate('verify'); }; @@ -47,7 +50,7 @@ const CredentialFields = () => {

Log in

{fail ?

Invalid credentials

: null} - +
@@ -82,6 +85,7 @@ const TwoFactor = () => { const [fail, setFail] = useState(false); const [, setUser] = useLoginContext(); const navigate = useNavigate(); + const twoFactorClick = async () => { const code = document.getElementById('2faCode').value; if (!code) return; @@ -89,7 +93,7 @@ const TwoFactor = () => { const result = await post('/api/login/verify', { code }); if (result.status === 200) { setUser(await fetchUser()); - return navigate('/home', { replace: true }); + return navigate('/home'); } setFail(true); }; @@ -109,7 +113,7 @@ const Login = () => {
- } /> + } /> } /> diff --git a/src/pages/Register.js b/src/pages/Register.js index 2619612..017741d 100644 --- a/src/pages/Register.js +++ b/src/pages/Register.js @@ -13,7 +13,9 @@ const Register = () => { document.body.classList.add('bg-triangles'); const code = params.get('code'); - const submit = async () => { + const submit = async (event) => { + + event.preventDefault(); const username = document.getElementById('username').value; const password = document.getElementById('password').value; if (!username.length || !password.length) return; @@ -21,6 +23,7 @@ const Register = () => { const response = await post('/api/register', { username, password, code }); if (response.status !== 200) return setError(response.message); navigate('/login'); + }; return
@@ -35,7 +38,7 @@ const Register = () => { {error &&

{error}

} - +