2.8 KiB
Agents Documentation
This file contains important project-specific context for Claude Code agents working on this repository.
Redemption Code System
IMPORTANT: Codes can only be redeemed on the website, NOT in the mobile app.
Apple's App Store guidelines require that any premium features purchased within an iOS app must go through In-App Purchase. Adding a redemption code feature to the mobile app would violate these guidelines and risk app rejection.
Overview
Promotional codes that grant users premium access without going through RevenueCat/App Store subscription flow.
Database Schema
redemption_codes table:
id(UUID) - Primary keycode(TEXT, UNIQUE) - The redemption codedescription(TEXT) - Optional descriptionmax_uses(INTEGER) - Maximum number of redemptions allowedcurrent_uses(INTEGER) - Current number of redemptionsexpires_at(TIMESTAMPTZ) - Optional expiration dateis_active(BOOLEAN) - Whether the code can be redeemedcreated_by(UUID) - Admin who created the codecreated_at(TIMESTAMPTZ)updated_at(TIMESTAMPTZ)
code_redemptions table:
id(UUID) - Primary keycode_id(UUID) - Reference to redemption_codesuser_id(UUID) - User who redeemed the coderedeemed_at(TIMESTAMPTZ)- UNIQUE constraint on (code_id, user_id) - Each user can only redeem a code once
Components
-
Admin UI (
apps/admin/src/pages/RedemptionCodesPage.tsx)- Super admins can generate codes
- View all codes with usage stats
- Toggle active/inactive
- View who redeemed each code
- Delete codes
-
Edge Function (
apps/supabase/functions/redeem-code/index.ts)- Unauthenticated - accepts email + code in request body
- Calls the
redeem_code_by_email()database function - Returns success/error response
-
Database Function (
redeem_code_by_email(p_email TEXT, p_code TEXT))- Atomic operation with row locking
- Looks up user by email (must have signed up in app first)
- Validates: code exists, is active, not expired, has uses remaining
- Checks user hasn't already redeemed
- Records redemption in
code_redemptions - Increments
current_uses - Sets
profiles.is_premium = true
-
Web UI (
apps/web/app/redeem/page.tsx)- Public page at
/redeem - User enters email + redemption code
- Calls edge function via fetch
- Shows success or error message
- Public page at
Environment Variables
The web app requires:
NEXT_PUBLIC_SUPABASE_URL- Supabase project URL for API calls
DO NOT
- DO NOT add redemption code UI to the mobile app
- DO NOT create any in-app mechanism to bypass App Store purchases
- DO NOT expose the redeem endpoint in mobile app Supabase calls