typebase-io-cli auth
Manage authentication tables.
Last updated on
auth generate
Add authentication tables to your database schema.
npx typebase-io-cli auth generateThis command:
- Reads your
auth.tsconfiguration - Generates the required tables (
users,sessions,accounts,verifications) - Appends them to
db/schema.ts - Updates
db/relations.ts - Generates and saves
BETTER_AUTH_SECRETin your local.envif it doesn't already exist - Regenerates type definitions
How it edits relations.ts
The auth tables are registered inside your existing q.defineRelations(schema, (r) => ({ ... })) call, and your own entries are kept as they are.
The relations it adds go through whatever your callback calls its parameter: (helpers) => ... gets helpers.one.users(...). A callback with no
parameter, such as () => ({ todos: {} }), gets an r added.
The callback has to be an inline arrow function returning an object literal, with a named parameter or none. A destructured one, like
({ one, many }) => ..., leaves no name to write the auth relations through, so the command stops and changes no files. Name the parameter and run it
again.
Prerequisites
- A
typebase/auth.tsfile must exist - A
typebase/db/schema.tsfile must exist
In migrations mode
If your project uses migrations, auth generate also records a migration for the tables it just added:
✔ Auth tables added to schema.ts and relations.ts.
✔ Migration written to typebase/db/migrations/20260101120000_auth_tables.auth generate is one of the few commands that edits your schema for you, and what it adds is known and bounded, so it records the migration itself
rather than leaving your schema files and your history to drift apart. Re-running it when the auth tables are already there and unchanged records
nothing.
See the Authentication page for full details on setting up auth.