Overview
src/lib/referral.ts stores referral codes in a mockReferralCodes Map in module memory. Every server restart wipes all referral codes, making referral links invalid. Referral counts are lost, and the feature provides no real value in production.
Specifications
Features:
- Referral codes are stored in the database and persist indefinitely
- Referral counts are accurate and survive restarts
Tasks:
- Create a
referrals table: (code TEXT PRIMARY KEY, owner_email TEXT, owner_id UUID, referral_count INT DEFAULT 0, created_at TIMESTAMPTZ)
- Replace all
mockReferralCodes Map operations with parameterized SQL queries
- On user signup, generate and store the code in the database
- Implement
getReferralCount() with a SELECT COUNT(*) from a referred_users join table
Impacted Files:
src/lib/referral.ts
src/app/api/auth/signup/route.ts
src/lib/db/ (new migration)
Acceptance Criteria
- Referral codes persist across server restarts
referralCodeExists() queries the database
- Referral count increments correctly in the database on successful signup
Overview
src/lib/referral.tsstores referral codes in amockReferralCodesMapin module memory. Every server restart wipes all referral codes, making referral links invalid. Referral counts are lost, and the feature provides no real value in production.Specifications
Features:
Tasks:
referralstable:(code TEXT PRIMARY KEY, owner_email TEXT, owner_id UUID, referral_count INT DEFAULT 0, created_at TIMESTAMPTZ)mockReferralCodesMap operations with parameterized SQL queriesgetReferralCount()with aSELECT COUNT(*)from areferred_usersjoin tableImpacted Files:
src/lib/referral.tssrc/app/api/auth/signup/route.tssrc/lib/db/(new migration)Acceptance Criteria
referralCodeExists()queries the database