为 BetterAuth 做出贡献

感谢你对为 Better Auth 做出贡献的兴趣!本指南是关于如何为 Better Auth 做出贡献的简明指南。

【Thank you for your interest in contributing to Better Auth! This guide is a concise guide to contributing to Better Auth.】

入门

【Getting Started】

在深入之前,这里有一些重要的资源:

【Before diving in, here are a few important resources:】

开发环境设置

【Development Setup】

开始开发步骤:

【To get started with development:】

确保你已经安装了 Node.JS,最好是 LTS 版本。

1. 分叉仓库

访问 https://github.com/better-auth/better-auth

点击右上角的“Fork”按钮。

2. 克隆你的分叉

# Replace YOUR-USERNAME with your GitHub username
git clone https://github.com/YOUR-USERNAME/better-auth.git
cd better-auth

3. 安装依赖

确保你已经安装了 pnpm

pnpm install

4. 准备 ENV 文件

复制示例环境文件以创建你的新 .env 文件。

cp -n ./docs/.env.example ./docs/.env

做出更改

【Making changes】

一旦你有了想要贡献的想法,就可以开始进行更改。以下是一些入门步骤:

【Once you have an idea of what you want to contribute, you can start making changes. Here are some steps to get started:】

1. 创建一个新分支

# Add upstream remote (if not already added)
git remote add upstream https://github.com/better-auth/better-auth.git

# Make sure you're on canary
git checkout canary

# Pull latest changes
git pull upstream canary

# Create and switch to a new branch
git checkout -b feature/your-feature-name

2. Start development server

启动开发服务器:

pnpm dev

启动文档服务器:

pnpm -F docs dev

3. Make Your Changes

问题和修复

【Issues and Bug Fixes】

  • 查看我们的 GitHub 问题 中标记为 good first issue 的任务
  • 在报告错误时,请包括重现步骤和预期行为
  • 请对你希望参与的议题发表意见,以避免重复工作

框架集成

【Framework Integrations】

我们欢迎贡献以支持更多框架:

【We welcome contributions to support more frameworks:】

  • 尽可能专注于与框架无关的解决方案
  • 保持集成最小化并易于维护
  • 所有集成目前都在主包中

插件开发

【Plugin Development】

  • 对于核心插件:请先提出问题以讨论你的想法
  • 对于社区插件:可以随意独立开发
  • 遵循我们的插件架构指南

文档

【Documentation】

  • 修复拼写错误和错误
  • 添加示例并澄清现有内容
  • 确保文档与代码变更保持同步

测试

【Testing】

我们使用 Vitest 进行测试。将测试文件放在它们所测试的源文件旁边:

【We use Vitest for testing. Place test files next to the source files they test:】

import { describe, it, expect } from "vitest";
import { getTestInstance } from "./test-utils/test-instance";

describe("Feature", () => {
    it("should work as expected", async () => {
        const { client } = await getTestInstance();
        // Test code here
        expect(result).toBeDefined();
    });
});

使用测试实例助手

【Using the Test Instance Helper】

测试实例辅助工具现在包括改进的异步上下文支持,用于管理用户会话:

【The test instance helper now includes improved async context support for managing user sessions:】

const { client, runWithUser, signInWithTestUser } = await getTestInstance();

// Run tests with a specific user context
await runWithUser("user@example.com", "password", async (headers) => {
    // All client calls within this block will use the user's session
    const response = await client.getSession();
    // headers are automatically applied
});

// Or use the test user with async context
const { runWithDefaultUser } = await signInWithTestUser();
await runWithDefaultUser(async (headers) => {
    // Code here runs with the test user's session context
});

测试最佳实践

【Testing Best Practices】

  • 编写清晰的提交信息
  • 更新文档以反映你的更改
  • 为新功能添加测试
  • 遵循我们的编码标准
  • 保持拉取请求专注于单一更改

需要帮助?

【Need Help?】

不要犹豫寻求帮助!你可以:

【Don't hesitate to ask for help! You can:】

感谢你为 Better Auth 做出贡献!

【Thank you for contributing to Better Auth!】

On this page