import { useEffect, useState } from "react"; import { useDebounce } from "use-debounce"; import { ThemeToggle } from "@/components/theme-toggle"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { GitSocialLink, SelfSocialLink } from "@/components/social-links"; import "@/App.css"; const uri = "https://login.microsoft.com/{tenant}/.well-known/openid-configuration"; function App() { const [input, setInput] = useState(location.hash.replace("#", "")); const [tenantId, setTenantId] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [domain, setDomain] = useDebounce(input, 500); const onChange = async (event: React.ChangeEvent) => setInput(event.target.value); useEffect(() => { location.hash = domain; if ( (!domain.includes("@") && !domain.includes(".")) || domain.includes(" ") || domain.endsWith(".") || domain.length < 3 || domain.length > 254 ) { setTenantId(null); setIsLoading(false); setError("Please enter a valid email address or domain."); return; } if (domain.includes("@")) { const parts = domain.split("@"); setIsLoading(false); setDomain(parts[parts.length - 1]); return; } setIsLoading(true); setError(null); (async function () { const response = await fetch(uri.replace("{tenant}", domain)); const body = await response.json(); if (!response.ok) { setTenantId(null); setIsLoading(false); setError(body.error_description.split(". ")[0]); return; } const myTenantId = body.authorization_endpoint.split("/")[3]; setTenantId(myTenantId); setIsLoading(false); })(); }, [domain, setDomain]); return ( <>
What's my Tenant Id?
Enter any email address or domain that your organization uses in Microsoft365/Azure.
{input && !isLoading && error && ( Error! {error} )} {isLoading && ( Loading... Querying Microsoft land... )} {!isLoading && tenantId && ( Tenant Found Your Tenant Id is {tenantId} )}
); } export default App;