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:
@@ -179,18 +179,24 @@ export const domainsRoutes: FastifyPluginAsync = async (app) => {
|
||||
});
|
||||
}
|
||||
|
||||
// If not verified, set/keep status as pending or failed
|
||||
await supabase
|
||||
.from("domains")
|
||||
.update({
|
||||
status: "pending",
|
||||
verified_at: null,
|
||||
})
|
||||
.eq("id", domainId);
|
||||
// A DNS CNAME lookup structurally cannot see the real target once the
|
||||
// record is proxied (Cloudflare hides it behind its own edge IPs) — so a
|
||||
// failed re-check here is inconclusive, not proof the domain broke.
|
||||
// Never downgrade a domain that was already verified; only a first-time
|
||||
// check is allowed to land on "pending".
|
||||
if (domain.status !== "verified") {
|
||||
await supabase
|
||||
.from("domains")
|
||||
.update({
|
||||
status: "pending",
|
||||
verified_at: null,
|
||||
})
|
||||
.eq("id", domainId);
|
||||
}
|
||||
|
||||
return reply.send({
|
||||
verified: false,
|
||||
domain: { ...domain, status: "pending", verified_at: null },
|
||||
verified: domain.status === "verified",
|
||||
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.`,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -168,6 +168,8 @@ export const restaurantsRoutes: FastifyPluginAsync = async (app) => {
|
||||
classic: "Classic Bistro",
|
||||
};
|
||||
|
||||
const { data: themeData } = await supabase.from("themes").select("id").eq("key", themeKey).maybeSingle();
|
||||
|
||||
let themeId = themeData?.id;
|
||||
if (!themeId) {
|
||||
const { data: newTheme } = await supabase
|
||||
|
||||
Reference in New Issue
Block a user