From 22deb7a44a2fa59790e6a2acead54976dd71cc69 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 15 Nov 2025 01:26:00 +0000 Subject: [PATCH] Create context for subdomain-based passport rendering (aethex.me / aethex.space) cgen-d354ca4c207a40e4bc71cc425d83f459 --- client/contexts/SubdomainPassportContext.tsx | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 client/contexts/SubdomainPassportContext.tsx diff --git a/client/contexts/SubdomainPassportContext.tsx b/client/contexts/SubdomainPassportContext.tsx new file mode 100644 index 00000000..d914842a --- /dev/null +++ b/client/contexts/SubdomainPassportContext.tsx @@ -0,0 +1,100 @@ +import { createContext, useContext, useEffect, useState } from "react"; + +interface SubdomainInfo { + subdomain: string; + domain: string; + isCreatorPassport: boolean; + isProjectPassport: boolean; +} + +interface SubdomainPassportContextType { + subdomainInfo: SubdomainInfo | null; + isLoading: boolean; + error: string | null; +} + +const SubdomainPassportContext = createContext( + { + subdomainInfo: null, + isLoading: true, + error: null, + } +); + +export const useSubdomainPassport = () => { + const context = useContext(SubdomainPassportContext); + if (!context) { + throw new Error( + "useSubdomainPassport must be used within SubdomainPassportProvider" + ); + } + return context; +}; + +export const SubdomainPassportProvider = ({ + children, +}: { + children: React.ReactNode; +}) => { + const [subdomainInfo, setSubdomainInfo] = useState( + null + ); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const detectSubdomain = () => { + try { + const hostname = window.location.hostname; + let subdomain = ""; + let domain = ""; + + if (hostname.includes("aethex.me")) { + const parts = hostname.split("."); + if (parts.length > 2) { + subdomain = parts[0]; + domain = "aethex.me"; + } + } else if (hostname.includes("aethex.space")) { + const parts = hostname.split("."); + if (parts.length > 2) { + subdomain = parts[0]; + domain = "aethex.space"; + } + } + + if (domain) { + const info: SubdomainInfo = { + subdomain, + domain, + isCreatorPassport: domain === "aethex.me", + isProjectPassport: domain === "aethex.space", + }; + setSubdomainInfo(info); + console.log("[SubdomainPassport] Detected:", info); + } else { + setSubdomainInfo(null); + } + } catch (e: any) { + console.error("[SubdomainPassport] Detection error:", e?.message); + setError("Failed to detect subdomain"); + } finally { + setIsLoading(false); + } + }; + + detectSubdomain(); + }, []); + + return ( + + {children} + + ); +};