From ae18f021c97e5a115ba8d8c3ffb6bdeaac14ac07 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Tue, 6 May 2025 10:23:50 -0700 Subject: [PATCH] docs: add dub plugin docs --- docs/components/sidebar-content.tsx | 27 +++-- docs/content/docs/plugins/dub.mdx | 146 ++++++++++++++++++++++++++++ docs/content/docs/plugins/polar.mdx | 9 +- 3 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 docs/content/docs/plugins/dub.mdx diff --git a/docs/components/sidebar-content.tsx b/docs/components/sidebar-content.tsx index 7b703afe..29a2e7b7 100644 --- a/docs/components/sidebar-content.tsx +++ b/docs/components/sidebar-content.tsx @@ -519,7 +519,6 @@ export const contents: Content[] = [ { title: "Kick", href: "/docs/authentication/kick", - isNew: true, icon: () => ( ( ( , }, { @@ -1477,7 +1473,6 @@ C0.7,239.6,62.1,0.5,62.2,0.4c0,0,54,13.8,119.9,30.8S302.1,62,302.2,62c0.2,0,0.2, { title: "Polar", href: "/docs/plugins/polar", - isNew: true, icon: () => ( ( ), }, + { + title: "Dub", + href: "/docs/plugins/dub", + isNew: true, + icon: () => ( + + + + ), + }, { title: "Community Plugins", href: "/docs/plugins/community-plugins", diff --git a/docs/content/docs/plugins/dub.mdx b/docs/content/docs/plugins/dub.mdx new file mode 100644 index 00000000..f2cb40ea --- /dev/null +++ b/docs/content/docs/plugins/dub.mdx @@ -0,0 +1,146 @@ +--- +title: Dub +description: Better Auth Plugin for Lead Tracking using Dub links and OAuth Linking +--- + +[Dub](https://dub.co/) is an open source modern link management platform for entrepreneurs, creators, and growth teams. + +This plugins allows you to track leads when a user signs up using a Dub link. It also adds OAuth linking support to allow you to build integrations extending Dub's linking management infrastructure. + +## Installation + + + + ### Install the plugin + First, install the plugin: + + ```package-install + @dub/better-auth + ``` + + + ### Install the Dub SDK + + Next, install the Dub SDK on your server: + + ```package-install + dub + ``` + + + ### Configure the plugin + + Add the plugin to your auth config: + + ```ts title="auth.ts" + import { betterAuth } from "better-auth" + import { dubAnalytics } from "@dub/better-auth" + import { dub } from "dub" + + export const auth = betterAuth({ + plugins: [ + dubAnalytics({ + dubClient: new Dub() + }) + ] + }) + ``` + + + + +## Usage + +### Lead Tracking + +By default, the plugin will track sign up events as leads. You can disable this by setting `disableLeadTracking` to `true`. + +```ts +import { dubAnalytics } from "@dub/better-auth"; +import { betterAuth } from "better-auth"; +import { Dub } from "dub"; + +const dub = new Dub(); + +const betterAuth = betterAuth({ + plugins: [ + dubAnalytics({ + dubClient: dub, + disableLeadTracking: true, // Disable lead tracking + }), + ], +}); +``` + +### OAuth Linking + +The plugin supports OAuth for account linking. + +First, you need to setup OAuth app in Dub. Dub supports OAuth 2.0 authentication, which is recommended if you build integrations extending Dub’s functionality [Learn more about OAuth](https://dub.co/docs/integrations/quickstart#integrating-via-oauth-2-0-recommended). + +Once you get the client ID and client secret, you can configure the plugin. + +```ts +dubAnalytics({ + dubClient: dub, + oauth: { + clientId: "your-client-id", + clientSecret: "your-client-secret", + }, +}); +``` + +And in the client, you need to use the `dubAnalyticsClient` plugin. + +```ts +import { createAuthClient } from "better-auth/client"; +import { dubAnalyticsClient } from "@dub/better-auth/client"; + +const authClient = createAuthClient({ + plugins: [dubAnalyticsClient()], +}); +``` + +To link account with Dub, you need to use the `dub.link`. + +```ts +const response = await authClient.dub.link({ + callbackURL: "/dashboard", // URL to redirect to after linking +}); +``` + +## Options + +You can pass the following options to the plugin: + +### `dubClient` + +The Dub client instance. + +### `disableLeadTracking` + +Disable lead tracking for sign up events. + +### `leadEventName` + +Event name for sign up leads. + +### `customLeadTrack` + +Custom lead track function. + +### `oauth` + +Dub OAuth configuration. + +### `oauth.clientId` + +Client ID for Dub OAuth. + +### `oauth.clientSecret` + +Client secret for Dub OAuth. + +### `oauth.pkce` + +Enable PKCE for Dub OAuth. diff --git a/docs/content/docs/plugins/polar.mdx b/docs/content/docs/plugins/polar.mdx index 93232452..6569c25f 100644 --- a/docs/content/docs/plugins/polar.mdx +++ b/docs/content/docs/plugins/polar.mdx @@ -6,7 +6,9 @@ description: Better Auth Plugin for Payment and Checkouts using Polar [Polar](https://polar.sh) is a developer first payment infrastructure. Out of the box it provides a lot of developer first integrations for payments, checkouts and more. This plugin helps you integrate Polar with Better Auth to make your auth + payments flow seamless. -This plugin is maintained by Polar team. For bugs, issues or feature requests, please visit the [Polar GitHub repo](https://github.com/polarsource/polar-adapters). + This plugin is maintained by Polar team. For bugs, issues or feature requests, + please visit the [Polar GitHub + repo](https://github.com/polarsource/polar-adapters). ## Installation @@ -75,11 +77,12 @@ This plugin is maintained by Polar team. For bugs, issues or feature requests, p }); ``` + -There is no client configuration required. You don't need to pass any configuration options to the `createAuthClient` function. + There is no client configuration required. You don't need to pass any + configuration options to the `createAuthClient` function. - For configuration options and more information, check out [Polar's Better Auth docs](https://docs.polar.sh/integrate/sdk/adapters/better-auth#configuration-options).