diff --git a/app/page.js b/app/page.js index 6a01d91..4d770d5 100644 --- a/app/page.js +++ b/app/page.js @@ -3,105 +3,70 @@ import { useState, useRef } from 'react'; import { useRouter } from 'next/navigation'; export default function LoginPage() { - const router = useRouter(); - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - const [captcha, setCaptcha] = useState(''); - const [error, setError] = useState(''); - const [success, setSuccess] = useState(''); - const captchaImgRef = useRef(null); + const router = useRouter(); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [captcha, setCaptcha] = useState(''); + const [error, setError] = useState(''); + const [success, setSuccess] = useState(''); + const captchaImgRef = useRef(null); - const refreshCaptcha = () => { - if (captchaImgRef.current) { - captchaImgRef.current.src = `/api/captcha?${new Date().getTime()}`; - } - }; + const refreshCaptcha = () => { + if (captchaImgRef.current) { + captchaImgRef.current.src = `/api/captcha?${new Date().getTime()}`; + } + }; - const handleLogin = async (e) => { - e.preventDefault(); - setError(''); - setSuccess(''); + const handleLogin = async (e) => { + e.preventDefault(); + setError(''); + setSuccess(''); - const res = await fetch('/api/login', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ email, password, captcha }) - }); + const res = await fetch('/api/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email, password, captcha }) + }); - const data = await res.json(); - if (!res.ok) { - setError(data.error); - refreshCaptcha(); - setCaptcha(''); - } else { - setSuccess(data.message); - router.push('/paper'); - } - }; + const data = await res.json(); + if (!res.ok) { + setError(data.error); + refreshCaptcha(); + setCaptcha(''); + } else { + setSuccess(data.message); + router.push(data.redirect || '/dash'); + } + }; - return ( -
-
-

Kalbot Access

+ return ( +
+
+

Kalbot Access

- {error &&
{error}
} - {success &&
{success}
} + {error &&
{error}
} + {success &&
{success}
} -
-
- - setEmail(e.target.value)} - /> -
-
- - setPassword(e.target.value)} - /> -
- -
- -
- captcha - -
- setCaptcha(e.target.value)} - /> -
- - -
+
+
+ + setEmail(e.target.value)} /> +
+
+ + setPassword(e.target.value)} /> +
+
+ +
+ captcha +
-
- ); + setCaptcha(e.target.value)} /> +
+ + +
+
+ ); }