Auth: document an import for the generated Better Auth tables (`userTable`, …)

未关闭 适合新手
#677 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
活跃
技术栈
sqlite, typescript

调研方向

在认证指南中记录 .void/better-auth-schema.ts 及其导出(userTable、sessionTable、accountTable、verificationTable),并包含一个指向 userTable.id 的外键示例。从现有的认证文档开始,那里描述了来自 void/auth 的 AuthUser 和 AuthSession 类型,然后为这些表添加一个章节。指南展示导入路径、列出稳定的导出并包含该示例即完成。公开导入的提案留给维护者决定。

由索引模型根据 Issue 内容生成。

描述

Summary

Void generates the Better Auth tables into .void/better-auth-schema.ts (userTable, sessionTable, accountTable, verificationTable), but the docs never say how to import them. The auth guide documents the AuthUser and AuthSession types from void/auth, but not the tables.

An app that queries its users, or has a table that belongs to a user, needs those tables. Today the only way to get them is to point at the generated file yourself, and a release that renames the file or its exports breaks that app without warning.

Example

An admin page that lists users:

// tsconfig.json: our own alias, next to the `@schema` one Void configures
"paths": {
  "@auth-schema": ["./.void/better-auth-schema.ts"]
}
// src/server/data/users.ts
import { userTable } from '@auth-schema';
import { db, desc } from 'void/db';

export function listUsers() {
  return db.select().from(userTable).orderBy(desc(userTable.createdAt));
}

A table whose rows belong to a user needs the same import for its foreign key:

// db/schema.ts
import { userTable } from '@auth-schema';
import { sqliteTable, text } from 'void/schema-d1';

export const postTable = sqliteTable('post', {
  id: text('id').primaryKey(),
  userId: text('user_id')
    .notNull()
    .references(() => userTable.id, { onDelete: 'cascade' }),
});
Why it matters
  • Users are app data too. Admin lists, "posts by this user" joins and foreign keys from app tables all need the table, not just the AuthUser type.
  • The generated file looks internal. It sits in .void/ with "Auto-generated by void — do not edit" at the top, so nothing tells an app it's safe to import. Its path and export names aren't documented, so an app can't tell what a release may change.
  • The tables already include the app's own columns. The generated userTable has the columns from Better Auth plugins and user.additionalFields (such as role and banned from admin()), so it's the right table to query. Copying it by hand would drift.
Proposal

In order of preference:

  1. A public import, for example import { userTable } from 'void/auth/schema', typed for the app's dialect and plugins.
  2. An auto-configured alias, like the existing @schema for db/schema.ts.
  3. At minimum, document .void/better-auth-schema.ts and its export names as stable, with an example of a foreign key to userTable.id in the database or auth guide.
Environment
  • void 1.5.0
  • D1 with Better Auth's admin() plugin
主要语言
TypeScript
星标
627
派生
66
平均合并
14 小时 38 分钟
30 天内合并 PR
179

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/void 的其他 Issue

查看 voidzero-dev/void 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。