- Created
user_creditstable with:credits_remaining: Default 50 credits for new userstotal_credits_used: Tracking lifetime usage- Unique constraint on
user_id
- Updated
handle_new_user()trigger to create credits entry on signup - Created
deduct_credit()function for safe credit deduction - Implemented RLS policies for secure access
-
Anonymous Users (localStorage-based):
- Max 3 free generations
- Max 3 free prompt views
- Tracked in
vibe_anonymous_limits - Cleared on login
-
Logged-in Users (database-based):
- 50 credits on signup
- Real-time credit checking
- Credit deduction with database transaction
-
Functions:
hasCredits(): Check if user can generatedeductCredit(): Deduct 1 credit (works for both anonymous and logged-in)getCreditsRemaining(): Get remaining credits countcanAnonymousView(): Check if anonymous user can view promptsincrementAnonymousView(): Track prompt views for anonymous users
- β Removed "Generate" link from navbar
- Users can only access /generate through:
- Hero page example prompts
- Direct URL (with credit checks)
- Credit Display: Shows remaining credits/generations in header
- Credit Check: Validates credits before generation
- Credit Deduction: Automatic 1 credit deduction on successful generation
- Limit Modal: Shows when credits exhausted with:
- Anonymous users: Sign up prompt
- Logged-in users: "No credits remaining" message
- Toast Notifications: Shows remaining credits after generation
- Anonymous Users:
- Limited to viewing 3 prompts max
- Tracks view count in localStorage
- Shows limit modal after 3 views with signup prompt
- Logged-in Users:
- Full access to all public prompts + own prompts
- No view limits
- Visit Home Page β Free access
- Click Example Prompt β Goes to /generate
- Generate Prompt β Uses 1 of 3 free generations
- After 3 Generations β Modal: "Sign up to continue"
- View Prompts β Can view 3 prompts
- After 3 Views β Modal: "Sign up for full access"
- Sign Up β Receives 50 credits automatically
- Navigate to /generate (via hero examples)
- See Credits β Display shows "X credits remaining"
- Generate Prompt β Deducts 1 credit
- View All Prompts β No limits, full access
- No Credits Left β Modal: "More features coming soon"
- β
RLS policies protect
user_creditstable - β
deduct_credit()function usesSECURITY DEFINER - β Anonymous tracking can't be manipulated server-side
- β Credit deduction is transactional (atomic)
- β No direct user access to modify credits
| User Type | Generations | Prompt Views | Storage |
|---|---|---|---|
| Anonymous | 3 free | 3 free | localStorage |
| Signed Up | 50 credits | Unlimited | Database |
| Out of Credits | 0 | Unlimited views | - |
- Add credit purchase system
- Add credit top-up functionality
- Track token usage (advanced pricing)
- Add subscription tiers
- Credit history/analytics page
- Email notifications for low credits
To apply the credit system:
# Option 1: Apply specific migration
npx supabase migration up
# Option 2: Reset database (development only)
npx supabase db reset
# Option 3: Apply to remote Supabase (production)
npx supabase db push- Anonymous user can generate 3 times
- Anonymous user sees limit modal after 3 generations
- Anonymous user can view 3 prompts
- Anonymous user sees limit modal after 3 views
- Signup creates user with 50 credits
- Credits display correctly in generate page
- Credit deduction works on generation
- Logged-in user with 0 credits sees modal
- Generate link removed from navbar
- Hero example prompts still work
- localStorage cleared on login
Implementation Date: November 13, 2025
Status: β
Complete and Functional