fix login

This commit is contained in:
Erik 2022-11-26 15:59:47 +02:00
parent 2cf359fa24
commit 0718f58529
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 13 additions and 6 deletions

View File

@ -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');
};
@ -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 = () => {
<div className='loginWrapper col-6 col-6-md col-3-lg'>
<Routes>
<Route path='/' element={<CredentialFields />} />
<Route exact path='/' element={<CredentialFields />} />
<Route path='/verify' element={<TwoFactor />} />
</Routes>

View File

@ -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 <div className="row is-center is-full-screen is-marginless">
@ -35,7 +38,7 @@ const Register = () => {
{error && <p>{error}</p>}
<form className="registerForm" action="/api/user">
<form className="registerForm">
<input autoComplete='off' placeholder='Username' required id='username' type='text' autoFocus />
<input autoComplete='off' placeholder='Password' required id='password' type='password' />
<button className="button primary" onClick={submit}>Register</button>