Skip to content

Affiliates

The Affiliates app lets business owners run an affiliate program. Affiliates sign up, receive referral links, and earn commissions on referred sales. The business owner can approve or reject affiliate applications and manage payouts from a single dashboard.

  • Affiliate dashboard with stats cards showing active affiliates, total referrals, and pending payouts
  • Affiliate approval workflow — pending affiliates can be approved or rejected inline with form actions
  • Referral tracking — each affiliate’s referral count is displayed alongside their profile
  • Payout management via a dedicated sub-route
RoutePurpose
/business/apps/affiliatesMain dashboard with stats and affiliate list
/business/apps/affiliates/payoutsPayout history and management

The app relies on three Supabase tables:

TableDescription
affiliatesStores affiliate records with status (pending, approved, rejected) and a program_owner_id FK to the business owner
affiliate_referralsTracks individual referrals with commission_amount and program_owner_id
profilesJoined via user:profiles(id, username, full_name, avatar_url) for affiliate display info

Stats are computed server-side in the load function rather than stored as aggregates:

  • Active affiliatescount query on affiliates where status = approved
  • Total referrals — count of rows in affiliate_referrals for the owner
  • Pending payouts — sum of commission_amount across all referrals

The main page (+page.svelte) uses:

  • Stats grid — three Card components displaying aggregate metrics with USD currency formatting
  • Affiliate list — iterates over affiliates showing avatar, name, referral count, and join date
  • Status badges — color-coded badges (pending = secondary, approved = default, rejected = destructive)
  • Inline actions — approve/reject buttons rendered as SvelteKit form actions with use:enhance for optimistic UI updates and toast notifications
  • SvelteKit form actions — the approve and reject actions update the affiliate’s status in Supabase, scoped to the program_owner_id for security
  • svelte-sonner — toast notifications on approve/reject actions
  • Supabase RLS — all queries are scoped to program_owner_id = user.id