import { useState, useEffect } from "react"; import logo from "../../assets/logo.png"; import { useNavigate } from "react-router-dom"; import { Mail, Lock, Eye, EyeOff } from 'lucide-react'; import { useLogin } from "../../hooks/useUser"; import { customToast } from "../utils/showToast"; import { CircleQuestionMark } from 'lucide-react'; const decodeJWT = (token: string) => { try { const base64 = token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"); const padded = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, "="); return JSON.parse(atob(padded)); } catch { return null; } }; export default function InternifyLogin() { const navigate = useNavigate(); const [email, setEmail] = useState(""); const [password, setPassword] = useState("") const [showPassword, setShowPassword] = useState(false); const { login, loading, error, setError } = useLogin(); useEffect(() => { if (!error) return; customToast.error("Login gagal", error); setError(null); }, [error, setError]); const handleSignIn = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (!email || !password) { setError("Email dan password wajib diisi."); return; } const data = await login(email, password); if (!data) return; const { token } = data; document.cookie = `token=${token}; path=/; SameSite=Strict`; const decoded = decodeJWT(token); const role = decoded?.role; if (role === "intern") { navigate("/intern"); } else if (role === "mentor" || role === "admin") { navigate("/mentor"); } else { setError("Role user tidak dikenali."); } }; return (
Logo

HUMIC LMS PORTAL

{/* MAIN CONTENT */}

Welcome back

Access your dashboard with your credentials.

{/* Input Email */}
setEmail(e.target.value)} className="w-full pl-10 pr-4 py-2.5 bg-white border border-card-outline rounded-lg text-sm placeholder-gray-400 focus:outline-none focus:border-red-500 focus:ring-1 focus:ring-red-500 transition-colors" />
setPassword(e.target.value)} className="w-full pl-10 pr-10 py-2.5 bg-white border border-card-outline rounded-lg text-sm placeholder-gray-400 focus:outline-none focus:border-red-500 focus:ring-1 focus:ring-red-500 transition-colors" />
{/* Forgot Password */}
Forgot Password?
{/* Divider & Support */}
SUPPORT

© 2026 Internify. CoE Humic Engineering.

Privacy Policy Terms of Service
); }