PhoenixKit.Users.Referrals (phoenix_kit v1.7.169)

Copy Markdown View Source

Core-side runtime bridge to the optional phoenix_kit_referrals package.

The referral-codes feature lives in the standalone phoenix_kit_referrals module. Core has no compile-time dependency on it — this facade resolves the installed module at runtime by its PhoenixKit.Module key ("referrals") via PhoenixKit.ModuleRegistry and dispatches through it.

When the package isn't installed (or doesn't export a given function) every call degrades safely: the system reads as disabled, lookups return nil, and use_code/2 is a no-op. That lets the registration / OAuth / magic-link flows treat referrals as optional — with the module absent, the referral field never appears and nothing is recorded.

The function surface here mirrors exactly what the signup flows call, so those call sites only had to swap their alias to this module.

Summary

Functions

Whether a referrals module is installed and enabled.

Whether the given code is expired (false when the module is absent).

Look up a referral code struct by its string, or nil.

Referral-codes configuration map. Disabled defaults when the module is absent.

Whether the given code hit its usage limit (false when absent).

Record a use of code_string by user_uuid.

Functions

enabled?()

Whether a referrals module is installed and enabled.

expired?(code)

Whether the given code is expired (false when the module is absent).

get_code_by_string(code_string)

Look up a referral code struct by its string, or nil.

get_config()

Referral-codes configuration map. Disabled defaults when the module is absent.

usage_limit_reached?(code)

Whether the given code hit its usage limit (false when absent).

use_code(code_string, user_uuid)

Record a use of code_string by user_uuid.

No-op returning {:error, :referrals_not_installed} when the module is absent.