feat: implement v9c feature enforcement system
Deploy Development / deploy (push) Successful in 34s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 12s

Backend:
- Add feature access checks to insights, export, import endpoints
- Enforce ai_calls, ai_pipeline, data_export, csv_import limits
- Return HTTP 403 (disabled) or 429 (limit exceeded)

Frontend:
- Create useFeatureAccess hook for feature checking
- Create FeatureGate/FeatureBadge components
- Gate KI-Analysen in Analysis page
- Gate Export/Import in Settings page
- Show usage counters (e.g. "3/10")

Docs:
- Update CLAUDE.md with implementation status

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-20 12:43:41 +01:00
1 parent 0210844522
commit 3745ebd6cd
12 files changed
+7176 -158

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import { useFeatureAccess } from '../hooks/useFeatureAccess'
/**
* Feature Gate Component
*
* Hides children if feature is not available.
* Optionally shows upgrade prompt or message.
*
* @param {string} feature - Feature slug (e.g. 'ai_calls', 'data_export')
* @param {ReactNode} children - Content to gate
* @param {ReactNode} fallback - Optional fallback when not allowed
* @param {boolean} showUpgradePrompt - Show upgrade message instead of hiding
*/
export function FeatureGate({ feature, children, fallback = null, showUpgradePrompt = false }) {
const { canUse, reason, loading, limit, remaining } = useFeatureAccess(feature)
// While loading, show children optimistically (better UX)
if (loading) return <>{children}</>
// If allowed, render children
if (canUse) return <>{children}</>
// Not allowed
if (showUpgradePrompt) {
return (
<div style={{
padding: 16,
background: 'var(--accent-light)',
borderRadius: 8,
textAlign: 'center',
color: 'var(--accent-dark)'
}}>
<div style={{ fontSize: 14, fontWeight: 600, marginBottom: 4 }}>
Feature nicht verfügbar
</div>
<div style={{ fontSize: 12 }}>
{reason === 'feature_disabled' && 'Dieses Feature ist in deinem Tier nicht enthalten.'}
{reason === 'limit_exceeded' && `Limit erreicht (${limit}). Upgrade für mehr Zugriff.`}
</div>
</div>
)
}
// Hide completely
return fallback
}
/**
* Feature Badge - Shows usage counter
*
* @param {string} feature - Feature slug
* @param {string} label - Label text (optional)
*/
export function FeatureBadge({ feature, label }) {
const { limit, used, remaining, loading } = useFeatureAccess(feature)
if (loading) return null
if (limit === null) return null // Unlimited
const percentage = limit > 0 ? (used / limit) * 100 : 0
const color = percentage > 90 ? 'var(--danger)' : percentage > 70 ? '#FFA726' : 'var(--accent)'
return (
<div style={{
display: 'inline-flex',
alignItems: 'center',
gap: 6,
padding: '4px 10px',
background: 'var(--surface2)',
borderRadius: 12,
fontSize: 11,
fontWeight: 600,
color: 'var(--text3)'
}}>
{label && <span>{label}:</span>}
<span style={{ color }}>{used}/{limit}</span>
{remaining !== null && remaining === 0 && <span style={{ color: 'var(--danger)' }}>⚠️</span>}
</div>
)
}