From 8c0d5e14f8bfd2754c2cbf20c9000f87ce82a671 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Tue, 28 Jul 2026 09:52:59 +0400 Subject: [PATCH] Fix send verification link routing --- functions/send-verification-link/handler.ts | 75 +++++++++------------ packages/fn-runtime/src/graphql.ts | 1 + 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/functions/send-verification-link/handler.ts b/functions/send-verification-link/handler.ts index 4e81bd768..856e18a14 100644 --- a/functions/send-verification-link/handler.ts +++ b/functions/send-verification-link/handler.ts @@ -27,30 +27,20 @@ const GetUser = gql` } `; -const GetDatabaseInfo = gql` - query GetDatabaseInfo($databaseId: UUID!) { - databases(where: { id: { equalTo: $databaseId } }, first: 1) { +const GetSiteInfo = gql` + query GetSiteInfo { + sites(first: 1) { nodes { - sites { + config + title + siteThemes(first: 1) { nodes { - domains { - nodes { - subdomain - domain - } - } - logo - title - siteThemes { - nodes { - theme - } - } - siteModules(where: { name: { equalTo: "legal_terms_module" } }) { - nodes { - data - } - } + theme + } + } + siteModules(where: { name: { equalTo: "legal_terms_module" } }) { + nodes { + data } } } @@ -82,7 +72,7 @@ const sendEmailLink = async ( params: SendEmailParams, context: SendEmailContext ) => { - const { client, meta, databaseId, env, log } = context; + const { client, env, log } = context; const isDryRun = parseEnvBoolean(env.SEND_VERIFICATION_LINK_DRY_RUN) ?? parseEnvBoolean(env.SEND_EMAIL_LINK_DRY_RUN) ?? @@ -123,41 +113,35 @@ const sendEmailLink = async ( return typeValidation; } - const databaseInfo = await meta.request(GetDatabaseInfo, { - databaseId - }); + const siteInfo = await client.request(GetSiteInfo); - const site = databaseInfo?.databases?.nodes?.[0]?.sites?.nodes?.[0]; + const site = siteInfo?.sites?.nodes?.[0]; if (!site) { throw new Error('Site not found for database'); } const legalTermsModule = site.siteModules?.nodes?.[0]; - const domainNode = site.domains?.nodes?.[0]; const theme = site.siteThemes?.nodes?.[0]?.theme; - if (!legalTermsModule || !domainNode || !theme) { + if (!legalTermsModule || !theme) { throw new Error('Missing site configuration for email'); } - const subdomain = domainNode.subdomain; - const domain = domainNode.domain; const supportEmail = legalTermsModule.data.emails.support; - const logo = site.logo?.url; + const logo = site.config?.logo?.url; const company = legalTermsModule.data.company; const website = company.website; const nick = company.nick; const name = company.name; const primary = theme.primary; - - const isLocalDomain = - domain === 'localhost' || - domain.startsWith('localhost') || - domain === '0.0.0.0'; - - const hostname = subdomain && !isLocalDomain - ? [subdomain, domain].join('.') - : domain; + const siteUrl = legalTermsModule.data.site?.siteUrl; + const siteHost = legalTermsModule.data.site?.host || legalTermsModule.data.site?.www; + const hostnameSource = siteUrl || siteHost; + const configuredUrl = + hostnameSource?.startsWith('http://') || hostnameSource?.startsWith('https://') + ? new URL(hostnameSource) + : null; + const hostname = configuredUrl?.hostname || hostnameSource || 'localhost'; const isLocalHost = hostname.startsWith('localhost') || @@ -170,7 +154,14 @@ const sendEmailLink = async ( : ''; const protocol = isLocalHost && isDryRun ? 'http' : 'https'; - const url = new URL(`${protocol}://${hostname}${localPort}`); + const url = new URL( + configuredUrl + ? configuredUrl.href + : `${protocol}://${hostname}${localPort}` + ); + if (configuredUrl && isLocalHost && isDryRun && env.LOCAL_APP_PORT && !url.port) { + url.port = env.LOCAL_APP_PORT; + } let subject: string; let subMessage: string; diff --git a/packages/fn-runtime/src/graphql.ts b/packages/fn-runtime/src/graphql.ts index a279f1c2b..b7c14094e 100644 --- a/packages/fn-runtime/src/graphql.ts +++ b/packages/fn-runtime/src/graphql.ts @@ -68,6 +68,7 @@ export const createClients = ( // names like identityProviders. Use X-Meta-Schema instead. const meta = createGraphQLClient(metaGraphqlUrl, env, { hostHeaderEnvVar: 'META_GRAPHQL_HOST_HEADER', + databaseId, useMetaSchema: true, });