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
| Key | Type | Description |
|---|---|---|
affiliate | Affiliate | null | Current affiliate profile data. |
stats | AffiliateStats | null | Clicks, conversions, earnings, and pending payout stats. |
referrals | Referral[] | List of referral records for the affiliate. |
payouts | Payout[] | List of payout history records. |
tiers | CommissionTier[] | All available commission tier definitions. |
isLoading | boolean | Loading flag — set manually before/after fetch calls. |
error | string | null | Error message, or null when no error. |
isAuthenticated | ComputedRef<boolean> | true when affiliate is non-null. |
isActive | ComputedRef<boolean> | true when affiliate.status === 'active'. |
referralUrl | ComputedRef<string> | Full referral URL with the affiliate's code appended. |
currentTier | ComputedRef<CommissionTier | undefined> | The commission tier matching the affiliate's current tier ID. |
nextTier | ComputedRef<CommissionTier | undefined> | The next tier above the affiliate's current tier. |
progressToNextTier | ComputedRef<number> | Progress percentage (0–100) towards the next tier. |
setAffiliate(data) | void | Set the affiliate state. |
setStats(data) | void | Set the stats state. |
setReferrals(data) | void | Set the referrals state. |
setPayouts(data) | void | Set the payouts state. |
setTiers(data) | void | Set the tiers state. |
reset() | void | Reset 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.
