diff --git a/src/scenes/Login.tsx b/src/scenes/Login.tsx index 211f4b1..c83b4c8 100644 --- a/src/scenes/Login.tsx +++ b/src/scenes/Login.tsx @@ -52,8 +52,29 @@ export default function Login() { } }; - const handleSSO = () => { - window.location.href = "/api/v1/auth/microsoft/login"; + const handleSSO = async () => { + setError(null); + setLoading(true); + try { + const probe = await fetch("/api/v1/auth/microsoft/login", { method: "GET", redirect: "manual" }); + if (probe.status >= 300 && probe.status < 400) { + window.location.href = "/api/v1/auth/microsoft/login"; + return; + } + if (probe.status === 503) { + setError("Microsoft sign-in is not yet enabled on this tenant. Use developer sign-in below for now."); + return; + } + if (probe.status === 404) { + setError("Microsoft sign-in is not wired to this environment yet. Use developer sign-in below for now."); + return; + } + window.location.href = "/api/v1/auth/microsoft/login"; + } catch (e) { + setError(`Microsoft sign-in unreachable: ${(e as Error).message}`); + } finally { + setLoading(false); + } }; return (