chore: Secure routes with auth middleware, update text and fix minor bugs

This commit is contained in:
2026-08-03 17:55:20 +05:30
parent 62d15c85f6
commit c2fab50749
68 changed files with 2515 additions and 6808 deletions

View File

@@ -10,17 +10,35 @@ import { Logo } from "@/components/Logo"
export default function LoginPage() {
const [showPassword, setShowPassword] = useState(false)
const [email, setEmail] = useState("demo@pragativeer.com")
const [password, setPassword] = useState("PragatiVeer@Secure2026!")
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [error, setError] = useState("")
const router = useRouter()
const handleLogin = (e: React.FormEvent) => {
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault()
if (email === "demo@pragativeer.com" && password === "PragatiVeer@Secure2026!") {
router.push("/dashboard")
} else {
setError("Invalid credentials. Please use the demo account.")
setError("")
try {
const res = await fetch("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password })
})
const data = await res.json()
if (data.success) {
if (data.role === "admin") {
router.push("/admin")
} else {
router.push("/dashboard")
}
} else {
setError(data.error || "Invalid email or password.")
}
} catch (err) {
setError("An error occurred. Please try again.")
}
}
return (
@@ -55,7 +73,9 @@ export default function LoginPage() {
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-foreground">Password</label>
<label className="text-sm font-bold text-foreground">
Password
</label>
<Link href="#" className="text-xs font-bold text-[#00F0FF] hover:text-[#00F0FF]/80 transition-colors">Forgot password?</Link>
</div>
<div className="relative">