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

Đang mở Phù hợp với người mới
#677 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
sqlite, typescript

Hướng nghiên cứu

Hãy ghi tài liệu cho .void/better-auth-schema.ts và các export của nó (userTable, sessionTable, accountTable, verificationTable) trong hướng dẫn xác thực, kèm ví dụ khóa ngoại tới userTable.id. Bắt đầu từ tài liệu xác thực hiện có, nơi mô tả các kiểu AuthUser và AuthSession từ void/auth, rồi thêm một mục cho các bảng. Hoàn thành khi hướng dẫn chỉ ra đường dẫn import, nêu tên các export ổn định và có ví dụ. Đề xuất import công khai được để maintainer quyết định.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
627
Fork
66
Merge trung bình
14 giờ 56 phút
Pull request đã merge (30 ngày)
170

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của voidzero-dev/void

Tất cả issue của voidzero-dev/void

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.