Typebase.
CLI

typebase-io-cli auth

Manage authentication tables.

Last updated on

auth generate

Add authentication tables to your database schema.

npx typebase-io-cli auth generate

This command:

  1. Reads your auth.ts configuration
  2. Generates the required tables (users, sessions, accounts, verifications)
  3. Appends them to db/schema.ts
  4. Updates db/relations.ts
  5. Generates and saves BETTER_AUTH_SECRET in your local .env if it doesn't already exist
  6. 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.ts file must exist
  • A typebase/db/schema.ts file 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.

On this page