Plan-Based Rendering 🎯
Learn how to render content conditionally based on user's subscription plan and configure plan quotas
Plan-Based Rendering 🎯
Indie Kit allows you to render different content based on the user's subscription plan. Let's explore how to implement plan-based rendering and configure plan quotas! 💫
Using useCurrentPlan Hook 🎨
The useCurrentPlan
hook provides information about the user's current subscription plan. Here's a complete example:
Configuring Plan Quotas ⚙️
Define plan quotas using the quotaSchema
in your database schema:
Using Quotas in Components 📊
Here's how to use quotas to control feature access:
Best Practices 💡
-
Graceful Degradation
- Always provide meaningful messages for restricted features
- Offer clear upgrade paths
- Handle edge cases (no plan, expired plan, etc.)
-
Performance
- Cache plan data when possible
- Avoid unnecessary re-renders
- Use loading states during plan checks
-
User Experience
- Show feature limitations before user actions
- Provide clear upgrade benefits
- Maintain consistent UI across plan levels
Common Patterns 🔄
Feature Gates
Usage Limits
Server-Side Plan Checks 🔒
API Routes with withAuthRequired
The withAuthRequired
middleware provides a powerful context object that includes session data and plan information:
Context Features 📋
The withAuthRequired
middleware provides:
session
: Authenticated user session datagetCurrentPlan()
: Helper function to fetch current planparams
: Route parameters (if any)
Server Components
For server components, you can still use the auth helper:
Now you can implement plan-based rendering and quota management in your Indie Kit application! Remember to always provide a great user experience regardless of the user's plan level. 🚀