// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1 "use client"; import { useEffect, useState } from "react"; import { callOAuthApi, type SessionView } from "@/lib/credentials"; import { format, getCredentialsMessages } from "@/lib/credentials-messages"; import type { Locale } from "@/lib/localization"; type HomeState = | { kind: "loading" } | { kind: "signedOut" } | { kind: "signedIn"; accountName: string }; /** The home page of credentials.progmasoft.com: where to go, signed in or not. */ export function CredentialsHome({ locale, consoleOrigin, }: { locale: Locale; consoleOrigin: string; }) { const { home, common } = getCredentialsMessages(locale); const [state, setState] = useState({ kind: "loading" }); useEffect(() => { const controller = new AbortController(); void callOAuthApi("/session", { signal: controller.signal, }).then((result) => { setState( result.kind === "ok" ? { kind: "signedIn", accountName: result.value.accountName } : { kind: "signedOut" }, ); }); return () => controller.abort(); }, []); async function signOut() { await callOAuthApi("/signout", { method: "POST" }); setState({ kind: "signedOut" }); } return ( <>
{state.kind === "loading" && (

{common.loading}

)} {state.kind === "signedOut" && ( <>

{home.signedOut}

{common.signIn}
)} {state.kind === "signedIn" && ( <>

{format(common.signedInAs, { name: state.accountName })}

)}

{home.discovery}:{" "} /.well-known/openid-configuration

); }