core: credit referral invites on first Lite checkout
Applies saved invites during Lite checkout so users who skip the referral page still credit the inviter. Avoids crediting already-active Lite workspaces so rewards stay tied to the first upgrade.
This commit is contained in:
parent
04c46117b9
commit
6a2cd816b7
4 changed files with 35 additions and 22 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { Actor } from "@opencode-ai/console-core/actor.js"
|
||||
import { Referral } from "@opencode-ai/console-core/referral.js"
|
||||
import { getRequestEvent } from "solid-js/web"
|
||||
|
||||
const REFERRAL_COOKIE = "oc_referral"
|
||||
const REFERRAL_MAX_AGE = 60 * 60 * 24 * 30
|
||||
|
|
@ -26,3 +28,17 @@ export function referralCodeFromCookieHeader(header: string | null) {
|
|||
?.slice(`${REFERRAL_COOKIE}=`.length),
|
||||
)
|
||||
}
|
||||
|
||||
export async function createReferralFromCookie() {
|
||||
const event = getRequestEvent()
|
||||
const referralCode = referralCodeFromCookieHeader(event?.request.headers.get("cookie") ?? null)
|
||||
if (!referralCode) return
|
||||
|
||||
await Referral.createFromAccount({
|
||||
accountID: Actor.account(),
|
||||
referralCode,
|
||||
}).catch((error) => {
|
||||
console.error("Referral create failed", error)
|
||||
})
|
||||
event?.response.headers.append("set-cookie", clearReferralCookie())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue