import { useTranslation } from "react-i18next"; import { type OAuthProvider } from "@shared/auth/spring/oauthTypes"; import { Button } from "@mantine/core"; import { oauthIconUrl, GENERIC_PROVIDER_ICON, } from "@shared/auth/ui/oauthIcons"; // Debug flag to show all providers for UI testing // Set to true to see all SSO options regardless of backend configuration export const DEBUG_SHOW_ALL_PROVIDERS = false; // OAuth provider configuration - maps provider ID to display info // Known providers get custom icons; unknown providers use generic SSO icon export const oauthProviderConfig: Record< string, { label: string; file: string } > = { google: { label: "Google", file: "google.svg" }, github: { label: "GitHub", file: "github.svg" }, apple: { label: "Apple", file: "apple.svg" }, azure: { label: "Microsoft", file: "microsoft.svg" }, keycloak: { label: "Keycloak", file: "keycloak.svg" }, cloudron: { label: "Cloudron", file: "cloudron.svg" }, authentik: { label: "Authentik", file: "authentik.svg" }, oidc: { label: "OIDC", file: "oidc.svg" }, }; // Icon URLs + GENERIC_PROVIDER_ICON come from the shared oauthIcons resolver. interface OAuthButtonsProps { onProviderClick: (provider: OAuthProvider) => void; isSubmitting: boolean; layout?: "vertical" | "grid" | "icons"; enabledProviders?: OAuthProvider[]; // List of full auth paths from backend (e.g., '/oauth2/authorization/google', '/saml2/authenticate/stirling') ctaPrefix?: string; styleVariant?: "neutral" | "tinted" | "outline" | "light"; demoMode?: boolean; useNewStyle?: boolean; } export default function OAuthButtons({ onProviderClick, isSubmitting, layout = "vertical", enabledProviders = [], ctaPrefix, styleVariant = "neutral", demoMode = false, useNewStyle = false, }: OAuthButtonsProps) { const { t } = useTranslation(); // Debug mode: show all providers for UI testing const providersToShow = DEBUG_SHOW_ALL_PROVIDERS ? Object.keys(oauthProviderConfig) : enabledProviders; // Build provider list - extract provider ID from full path for display const providers = providersToShow.map((pathOrId) => { // Extract provider ID from full path (e.g., '/saml2/authenticate/stirling' -> 'stirling') const providerId = pathOrId.split("/").pop() || pathOrId; if (providerId in oauthProviderConfig) { // Known provider - use predefined icon and label return { id: pathOrId, // Keep full path for redirect providerId, // Store extracted ID for display lookup ...oauthProviderConfig[providerId], }; } // Unknown provider - use generic icon and capitalize ID for label return { id: pathOrId, // Keep full path for redirect providerId, // Store extracted ID for display lookup label: providerId.charAt(0).toUpperCase() + providerId.slice(1), file: GENERIC_PROVIDER_ICON, }; }); // If no providers are enabled, don't render anything if (providers.length === 0) { return null; } const isSingleProvider = providers.length === 1; const isTinted = styleVariant === "tinted"; const isOutline = styleVariant === "outline"; const isLight = styleVariant === "light"; const accentMap: Record = { google: "#4285F4", github: "#111827", apple: "#111827", azure: "#0078D4", keycloak: "#2C2C2C", cloudron: "#3B82F6", authentik: "#FA7B17", oidc: "#334155", }; if (layout === "icons") { return (
{providers.map((p) => (
))}
); } if (layout === "grid") { return (
{providers.map((p) => (
))}
); } return (
{providers.map((p) => (
))}
); }