import { useState } from 'react' import { supabase } from '../lib/supabase' import { MicrosoftIcon } from './MicrosoftIcon' interface LoginProps { onLoginSuccess: () => void } export function Login({ onLoginSuccess }: LoginProps) { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const enableMicrosoftLogin = import.meta.env.VITE_ENABLE_MICROSOFT_LOGIN === 'true' const handleLogin = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError(null) try { const { data, error } = await supabase.auth.signInWithPassword({ email, password, }) if (error) { setError(error.message) } else if (data.user) { onLoginSuccess() } } catch (err) { setError('An unexpected error occurred') console.error('Login error:', err) } finally { setLoading(false) } } const handleMicrosoftLogin = async () => { setLoading(true) setError(null) try { const { error } = await supabase.auth.signInWithOAuth({ provider: 'azure', options: { scopes: 'email openid profile', redirectTo: `${window.location.origin}/`, }, }) if (error) { setError(error.message) setLoading(false) } // If successful, user will be redirected to Microsoft login // and then back to the app, so we don't stop loading here } catch (err) { setError('An unexpected error occurred during Microsoft login') console.error('Microsoft login error:', err) setLoading(false) } } return (

Sign in to your account

RBAC Authentication System

setEmail(e.target.value)} />
setPassword(e.target.value)} />
{error && (
{error}
)}
{enableMicrosoftLogin && ( <>
Or continue with
)}
) }