@dub/better-auth

中文文档
0.0.6发布于 2025/10/06TypeScriptESM + CJS近 30 天下载 6.6万

Dub Better Auth Plugin

原始使用文档
文档目录14 节
  1. Installation
  2. Usage
  3. Lead Tracking
  4. OAuth
  5. Options
  6. dubClient
  7. disableLeadTracking
  8. leadEventName
  9. customLeadTrack
  10. oauth
  11. oauth.clientId
  12. oauth.clientSecret
  13. oauth.pkce
  14. License

Dub Analytics - Better Auth Plugin

Dub Analytics Plugin is a plugin for Dub that allows you to track conversion events in your Better Auth application.

Installation

npm install @dub/better-auth

Usage

Lead Tracking

By default, the plugin will track sign up events as leads. You can disable this by setting disableLeadTracking to true.

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,
    }),
  ],
});

OAuth

Dub Better Auth supports OAuth for authentication. You can configure the OAuth client ID and client secret in the dubAnalytics function.

dubAnalytics({
  dubClient: dub,
  oauth: {
    clientId: "your-client-id",
    clientSecret: "your-client-secret",
  },
});

And in the client, you need to use the dubAnalyticsClient plugin.

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.

const response = await authClient.dub.link({
  callbackURL: "/dashboard", // URL to redirect to after linking
});

Options

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.

License

MIT

版本与发布记录

@dub/better-auth 共发布 6 个版本,首次发布于 2025/05/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.6latest2025/10/061.1 年前
0.0.52025/09/151.2 年前
0.0.42025/08/271.2 年前
0.0.32025/06/271.4 年前
0.0.22025/05/071.5 年前
0.0.12025/05/061.5 年前

关于 @dub/better-auth 的常见问题

@dub/better-auth 是什么?

Dub Better Auth Plugin

如何安装 @dub/better-auth?

在项目目录运行 npm install @dub/better-auth,或使用 pnpm add / yarn add / bun add。

@dub/better-auth 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dub/better-auth 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dub/better-auth 可以商用吗?

@dub/better-auth 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dub/better-auth 的下载量有多少?

根据 npm 官方下载统计,@dub/better-auth 在 2026/10/13 – 2026/11/11 这 30 天内被下载 65,904 次,日均约 2,197 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dub/better-auth 还在维护吗?

最新版本 0.0.6 发布于 2025/10/06(1.1 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。