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

Aperta Adatta ai principianti
#677 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
sqlite, typescript

Direzione di ricerca

Documenta .void/better-auth-schema.ts e i suoi export (userTable, sessionTable, accountTable, verificationTable) nella guida all'autenticazione, con un esempio di chiave esterna verso userTable.id. Inizia dalla documentazione di autenticazione esistente, dove sono descritti i tipi AuthUser e AuthSession di void/auth, e aggiungi una sezione per le tabelle. Il lavoro è completo quando la guida mostra il percorso di import, indica gli export stabili e include l'esempio. La proposta di import pubblico resta una decisione dei maintainer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
627
Fork
66
Merge medio
14h 56m
PR unite (30g)
170

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di voidzero-dev/void

Tutte le issue di voidzero-dev/void

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.