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 小時 56 分鐘
30 天內合併 PR
170

環境準備

這個專案沒有提供開發容器、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 摘要。