fix(api): don't undo domain verification on DNS re-check, fix theme lookup crash

- domains.ts: a proxied Cloudflare custom hostname's real CNAME target
  is never visible to a plain DNS lookup, so a re-verify always fails
  and was silently downgrading already-verified domains back to
  pending. Only a first-time check can now land on pending.
- restaurants.ts: PUT /restaurants/:id/theme referenced an undeclared
  themeData variable (pre-existing tsc error on main, not introduced
  here) — added the missing themes-by-key lookup it depended on.
This commit is contained in:
AyrisAI
2026-08-20 05:25:50 +03:00
parent 77eecd53ac
commit e0581440cb
2 changed files with 18 additions and 10 deletions
+16 -10
View File
@@ -179,18 +179,24 @@ export const domainsRoutes: FastifyPluginAsync = async (app) => {
}); });
} }
// If not verified, set/keep status as pending or failed // A DNS CNAME lookup structurally cannot see the real target once the
await supabase // record is proxied (Cloudflare hides it behind its own edge IPs) — so a
.from("domains") // failed re-check here is inconclusive, not proof the domain broke.
.update({ // Never downgrade a domain that was already verified; only a first-time
status: "pending", // check is allowed to land on "pending".
verified_at: null, if (domain.status !== "verified") {
}) await supabase
.eq("id", domainId); .from("domains")
.update({
status: "pending",
verified_at: null,
})
.eq("id", domainId);
}
return reply.send({ return reply.send({
verified: false, verified: domain.status === "verified",
domain: { ...domain, status: "pending", verified_at: null }, domain: domain.status === "verified" ? domain : { ...domain, status: "pending", verified_at: null },
message: `Doğrulanamadı: ${dnsErrorDetails}\n\nLütfen alan adı yönetim panelinizden (Cloudflare, GoDaddy, Natro vb.) ${domain.hostname} için CNAME kaydını ${expectedTarget} adresine yönlendirin.`, message: `Doğrulanamadı: ${dnsErrorDetails}\n\nLütfen alan adı yönetim panelinizden (Cloudflare, GoDaddy, Natro vb.) ${domain.hostname} için CNAME kaydını ${expectedTarget} adresine yönlendirin.`,
}); });
}); });
+2
View File
@@ -168,6 +168,8 @@ export const restaurantsRoutes: FastifyPluginAsync = async (app) => {
classic: "Classic Bistro", classic: "Classic Bistro",
}; };
const { data: themeData } = await supabase.from("themes").select("id").eq("key", themeKey).maybeSingle();
let themeId = themeData?.id; let themeId = themeData?.id;
if (!themeId) { if (!themeId) {
const { data: newTheme } = await supabase const { data: newTheme } = await supabase