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

Abierto Apto para principiantes
#677 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
62/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
sqlite, typescript

Línea de trabajo

Documenta .void/better-auth-schema.ts y sus exports (userTable, sessionTable, accountTable, verificationTable) en la guía de autenticación, con un ejemplo de clave foránea a userTable.id. Empieza en la documentación de autenticación existente, donde se describen los tipos AuthUser y AuthSession de void/auth, y añade una sección para las tablas. Se considera terminado cuando la guía muestra la ruta de importación, nombra los exports estables e incluye el ejemplo. La propuesta de importación pública queda como decisión de los maintainers.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
TypeScript
Estrellas
627
Forks
66
Merge medio
14 h 56 min
PR fusionados (30 d)
170

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de voidzero-dev/void

Todos los issues de voidzero-dev/void

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.