feat: referral (#3761)
Co-authored-by: DIYgod <i@diygod.me> Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
co-authored by
DIYgod
Innei
parent
79c9b05246
commit
30bb37c7b9
@@ -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}`
|
||||
|
||||
+25324
-20827
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user