import { useMsal } from '@azure/msal-react'; import { useState } from 'react'; import { loginRequest } from '../config/authConfig'; import { PersonIcon, ExitIcon } from '@radix-ui/react-icons'; export function AuthButton() { const { instance, accounts } = useMsal(); const [isLoading, setIsLoading] = useState(false); const handleLogin = async () => { setIsLoading(true); try { await instance.loginPopup(loginRequest); } catch (error) { console.error('Login failed:', error); } finally { setIsLoading(false); } }; const handleLogout = async () => { setIsLoading(true); try { await instance.logoutPopup({ postLogoutRedirectUri: '/', mainWindowRedirectUri: '/', }); } catch (error) { console.error('Logout failed:', error); } finally { setIsLoading(false); } }; const isAuthenticated = accounts.length > 0; const userName = accounts[0]?.username || accounts[0]?.name || 'User'; if (isAuthenticated) { return (