You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9bf8513
Browse filesBrowse the repository at this point in the historyBrowse files
## Summary
Documents how to import and use Void's generated Better Auth Drizzle
tables.
## Changes
- Documented the generated Better Auth tables and their exports.
- Added import and user-query examples.
- Added a foreign-key reference example.
- Explained the TypeScript path alias setup.
## Scope
Documentation-only. No logic changes.
Closes#677
Import `AuthUser` and `AuthSession` from `void/auth` for type annotations. They include the fields your Better Auth plugins and `user.additionalFields` add, such as `role` from `admin()`. See their fields in the [API reference](../reference/api/auth.md#authuser).
123
123
124
+
## Querying Authentication Tables
125
+
126
+
When authentication is enabled, Void generates the Better Auth Drizzle schema in `.void/better-auth-schema.ts`.
127
+
The generated file exports the core authentication tables:
128
+
129
+
-`userTable`
130
+
-`sessionTable`
131
+
-`accountTable`
132
+
-`verificationTable`
133
+
134
+
Configured Better Auth plugins may also contribute additional tables.
135
+
136
+
The generated file path and core table export names are documented integration points. You can import these exports directly rather than recreating the tables in your application.
137
+
138
+
To import these tables into your application, add a TypeScript path alias to your root `tsconfig.json`:
139
+
140
+
```json
141
+
{
142
+
"compilerOptions": {
143
+
"paths": {
144
+
"@auth-schema": ["./.void/better-auth-schema.ts"]
145
+
}
146
+
}
147
+
}
148
+
```
149
+
150
+
If your `tsconfig.json` already has a `paths` mapping, add `@auth-schema` to the existing mapping rather than replacing it.
151
+
152
+
If your project extends `.void/tsconfig.json` and defines its own `paths`, make sure to retain any mappings from the generated configuration that your project uses, such as `@schema`.
153
+
154
+
You can now import and query authentication tables:
This example assumes the default text ID strategy. If you configure `advanced.database.generateId: 'serial'`, use an integer foreign-key column to match the generated user ID.
180
+
181
+
The example above uses SQLite/D1. For PostgreSQL and MySQL, use the corresponding schema modules: `void/schema-pg` and `void/schema-mysql`.
182
+
183
+
The generated schema is managed by Void. Do not edit `.void/better-auth-schema.ts` manually, as Void may regenerate it during its build or preparation process.
184
+
124
185
## Behavior
125
186
126
187
Auth sessions use the same database as your app. Void creates `BETTER_AUTH_SECRET` on deploy if it is missing and reuses it on later deploys.
0 commit comments