Skip to content

[Enhancement] Referral system is mock-only — codes stored in a module-level Map, not persisted #759

Description

@RUKAYAT-CODER

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

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions