From 28395644697082fa0a05cd2fcb33cf0debd62805 Mon Sep 17 00:00:00 2001 From: chahinebrini Date: Thu, 21 May 2026 18:09:42 +0200 Subject: [PATCH] fix(custom-domains): Per-Bucket-Limit-Check via Backend counts/limits Web-/Mail-Limit getrennt gegen apiCounts/apiLimits geprueft (Single Source of Truth); Legacy-Response ohne counts/limits faellt auf Backend-Rejection zurueck. Co-Authored-By: Claude Opus 4.7 --- apps/rebreak-native/hooks/useCustomDomains.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/rebreak-native/hooks/useCustomDomains.ts b/apps/rebreak-native/hooks/useCustomDomains.ts index 8e7b2b5..c05cc11 100644 --- a/apps/rebreak-native/hooks/useCustomDomains.ts +++ b/apps/rebreak-native/hooks/useCustomDomains.ts @@ -145,8 +145,20 @@ export function useCustomDomains(plan: Plan): UseCustomDomainsReturn { const resolvedKind: 'web' | 'mail' = kind ?? (input.includes('@') ? 'mail' : 'web'); if (resolvedKind === 'web' && !isValidDomain(input)) return { ok: false, error: 'invalid_domain' }; if (resolvedKind === 'mail' && !input.trim()) return { ok: false, error: 'invalid_pattern' }; - const tier = deriveTier(plan, domains); - if (tier.atLimit) return { ok: false, error: 'limit_reached' }; + // Per-Bucket-Limit-Check via Backend-counts/limits (Single Source of Truth). + // Wenn API noch keine counts/limits geliefert hat (Legacy-Response) → skip, + // Backend rejected dann mit WEB_LIMIT_REACHED / MAIL_LIMIT_REACHED. + if (apiCounts && apiLimits) { + const bucket = resolvedKind; + const used = apiCounts[bucket] ?? 0; + const cap = apiLimits[bucket] ?? Infinity; + if (used >= cap) { + return { + ok: false, + error: bucket === 'mail' ? 'mail_limit_reached' : 'web_limit_reached', + }; + } + } const pattern = resolvedKind === 'web' ? normalizeDomain(input) : input.trim(); const body: Record = { pattern }; if (kind !== undefined) body.kind = kind;