diff --git a/src/components/site/SiteLayout.tsx b/src/components/site/SiteLayout.tsx index b61edede..55424fa1 100644 --- a/src/components/site/SiteLayout.tsx +++ b/src/components/site/SiteLayout.tsx @@ -8,6 +8,8 @@ import { BlockchainInfo } from "~/components/common/BlockchainInfo" import { useGetSiteSubscriptions } from "~/queries/site" import { useGetSite } from "~/queries/site" import { useGetPage } from "~/queries/page" +import { OUR_DOMAIN, SITE_URL } from "~/lib/env" +import { IS_PROD } from "~/lib/constants" export type SiteLayoutProps = { children: React.ReactNode @@ -32,6 +34,18 @@ export const SiteLayout: React.FC = ({ children, title }) => { siteId: domainOrSubdomain, }) + useEffect(() => { + if (site.data) { + if ( + window.location.host.split(".").slice(-2).join(".") !== OUR_DOMAIN && + window.location.host !== site.data?.custom_domain && + IS_PROD + ) { + window.location.href = SITE_URL + } + } + }, [site.isSuccess, site.data]) + return ( <> { ) const txt = await res.json() const tenant = txt?.Answer?.[0]?.data.replace(/^"|"$/g, "") - if (tenant) { - const res = await fetch( - `https://indexer.crossbell.io/v1/handles/${tenant}/character`, - ) - const char = await res.json() - if (!char?.metadata?.content && char?.metadata?.uri) { - char.metadata.content = await ( - await fetch( - toGateway(char?.metadata?.uri, { - needRequestAtServerSide: true, - }), - { - ...(typeof window === "undefined" && { - headers: { - "User-Agent": - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36", - }, - }), - }, - ) - ).json() - } - const customDomain = - char?.metadata?.content?.attributes?.find( - (a: any) => a.trait_type === "xlog_custom_domain", - )?.value || "" - if (customDomain && customDomain === host) { - return { - subdomain: tenant, - } - } + return { + subdomain: tenant, } } }