import { useMsal } from '@azure/msal-react'; import { loginRequest } from '../auth/authConfig'; import { useNavigate, useLocation } from 'react-router-dom'; import { useState, useEffect } from 'react'; import styles from './Login.module.css'; import agentDiagram from '../assets/Frame 43.png'; import logo from '../assets/LogoPowerOn.png'; import { useAuth, useMsalAuth } from '../hooks/useAuthentication'; function Login() { const { instance, accounts, inProgress } = useMsal(); const navigate = useNavigate(); const location = useLocation(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const { login, error: loginError, isLoading: isLoginLoading } = useAuth(); const { loginWithMsal, error: msalError, isLoading: isMsalLoading } = useMsalAuth(); // Get the page the user was trying to visit const from = location.state?.from?.pathname || "/"; // Debug information about accounts useEffect(() => { if (accounts.length > 0) { console.log("MSAL accounts found:", accounts.map(acc => ({ username: acc.username, name: acc.name, idTokenClaims: acc.idTokenClaims }))); } else { console.log("No MSAL accounts found"); } }, [accounts]); const handleMsalLogin = async () => { try { console.log("Attempting MSAL login..."); const response = await loginWithMsal(); console.log("MSAL login successful:", response); navigate(from, { replace: true }); } catch (error) { console.error("MSAL login failed:", error); } }; const handleCredentialLogin = async () => { try { await login(username, password); navigate(from, { replace: true }); } catch (error) { console.error("Login failed:", error); } }; return (