X Enterprises
Composables

useAffiliate

SSR-safe state management for affiliate data, stats, referrals, payouts, and commission tiers — with computed helpers and setter methods.

useAffiliate

SSR-safe state composable for affiliate program data using Nuxt useState. The consuming app is responsible for fetching data from its API and calling the provided setters. All XAF* dashboard components read state from this composable, so calling setAffiliate() and setStats() automatically updates the entire UI.

Usage

const {
  affiliate,
  stats,
  referrals,
  payouts,
  tiers,
  isLoading,
  error,
  isAuthenticated,
  isActive,
  referralUrl,
  currentTier,
  nextTier,
  progressToNextTier,
  setAffiliate,
  setStats,
  setReferrals,
  setPayouts,
  setTiers,
  reset,
} = useAffiliate()

Returns

KeyTypeDescription
affiliateAffiliate | nullCurrent affiliate profile data.
statsAffiliateStats | nullClicks, conversions, earnings, and pending payout stats.
referralsReferral[]List of referral records for the affiliate.
payoutsPayout[]List of payout history records.
tiersCommissionTier[]All available commission tier definitions.
isLoadingbooleanLoading flag — set manually before/after fetch calls.
errorstring | nullError message, or null when no error.
isAuthenticatedComputedRef<boolean>true when affiliate is non-null.
isActiveComputedRef<boolean>true when affiliate.status === 'active'.
referralUrlComputedRef<string>Full referral URL with the affiliate's code appended.
currentTierComputedRef<CommissionTier | undefined>The commission tier matching the affiliate's current tier ID.
nextTierComputedRef<CommissionTier | undefined>The next tier above the affiliate's current tier.
progressToNextTierComputedRef<number>Progress percentage (0–100) towards the next tier.
setAffiliate(data)voidSet the affiliate state.
setStats(data)voidSet the stats state.
setReferrals(data)voidSet the referrals state.
setPayouts(data)voidSet the payouts state.
setTiers(data)voidSet the tiers state.
reset()voidReset all state to initial values.

AI Context

composable: useAffiliate
package: "@xenterprises/nuxt-x-affiliate"
use-when: >
  Managing affiliate program state in a Nuxt app using nuxt-x-affiliate.
  Fetch data from your API and call setAffiliate(), setStats(),
  setReferrals(), setPayouts(), and setTiers() to populate state — all
  XAF* components read from this shared state automatically. Use the
  computed helpers (isActive, referralUrl, currentTier, progressToNextTier)
  to drive conditional UI or display calculated values without duplicating
  logic. Call reset() on logout.
Copyright © 2026