feat: referral (#3761)

Co-authored-by: DIYgod <i@diygod.me>
Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
Stephen Zhou
2025-07-10 09:47:11 +08:00
committed by GitHub
co-authored by DIYgod Innei
parent 79c9b05246
commit 30bb37c7b9
62 changed files with 27487 additions and 20935 deletions
+19 -1
View File
@@ -1,3 +1,4 @@
import { stripeClient } from "@better-auth/stripe/client"
import { IN_ELECTRON } from "@follow/shared"
import type { authPlugins } from "@follow/shared/hono"
import type { BetterAuthClientPlugin, BetterFetchOption } from "better-auth/client"
@@ -31,6 +32,7 @@ export const baseAuthPlugins = [
},
}),
twoFactorClient(),
stripeClient({ subscription: true }),
] satisfies BetterAuthClientPlugin[]
export type AuthClient<ExtraPlugins extends BetterAuthClientPlugin[] = []> = ReturnType<
@@ -54,7 +56,19 @@ export class Auth {
this.authClient = createAuthClient({
baseURL: `${this.options.apiURL}/better-auth`,
plugins: baseAuthPlugins,
fetchOptions: this.options.fetchOptions,
fetchOptions: {
...this.options.fetchOptions,
onRequest: (context) => {
const referralCode = localStorage.getItem(getStorageNS("referral-code"))
if (referralCode) {
context.headers.set("folo-referral-code", referralCode)
}
this.options.fetchOptions?.onRequest?.(context)
return context
},
},
})
}
@@ -86,3 +100,7 @@ export class Auth {
}
}
}
// copy from packages/internal/utils/src/ns.ts
const ns = "follow"
const getStorageNS = (key: string) => `${ns}:${key}`
File diff suppressed because it is too large Load Diff