src/db/schema.ts using Drizzle ORM. All tables are auto-generated by Better Auth to handle authentication, sessions, and OAuth.
Schema File Location
Better Auth Tables
Better Auth automatically creates and manages five tables for authentication. You don’t need to manually create these tables - they’re generated when you runnpm run db:push or npm run db:migrate.
User Table
Stores user account information and profiles.src/db/schema.ts
| Column | Type | Constraints | Description |
|---|---|---|---|
id | text | Primary Key | Unique user identifier |
name | text | Not Null | User’s display name |
email | text | Not Null, Unique | User’s email address |
emailVerified | boolean | Not Null, Default: false | Email verification status |
image | text | Nullable | User’s profile image URL |
createdAt | timestamp | Not Null, Auto | Account creation timestamp |
updatedAt | timestamp | Not Null, Auto | Last update timestamp |
Session Table
Tracks active user sessions with device information.src/db/schema.ts
| Column | Type | Constraints | Description |
|---|---|---|---|
id | text | Primary Key | Unique session identifier |
expiresAt | timestamp | Not Null | Session expiration time |
token | text | Not Null, Unique | Session token |
createdAt | timestamp | Not Null | Session creation time |
updatedAt | timestamp | Not Null | Last session update |
ipAddress | text | Nullable | Client IP address |
userAgent | text | Nullable | Client user agent string |
userId | text | Foreign Key, Not Null | References user.id (cascade delete) |
userId→user.id(one-to-many: one user can have multiple sessions)- Cascade delete: deleting a user removes all their sessions
Account Table
Stores OAuth provider accounts and authentication credentials.src/db/schema.ts
| Column | Type | Constraints | Description |
|---|---|---|---|
id | text | Primary Key | Unique account identifier |
accountId | text | Not Null | Provider-specific account ID |
providerId | text | Not Null | Auth provider (e.g., “google”, “credential”) |
userId | text | Foreign Key, Not Null | References user.id (cascade delete) |
accessToken | text | Nullable | OAuth access token |
refreshToken | text | Nullable | OAuth refresh token |
idToken | text | Nullable | OAuth ID token |
accessTokenExpiresAt | timestamp | Nullable | Access token expiration |
refreshTokenExpiresAt | timestamp | Nullable | Refresh token expiration |
scope | text | Nullable | OAuth scope |
password | text | Nullable | Hashed password (for credential provider) |
createdAt | timestamp | Not Null | Account creation time |
updatedAt | timestamp | Not Null | Last update time |
userId→user.id(one-to-many: one user can have multiple provider accounts)- Cascade delete: deleting a user removes all their accounts
Verification Table
Stores email verification tokens and other verification codes.src/db/schema.ts
| Column | Type | Constraints | Description |
|---|---|---|---|
id | text | Primary Key | Unique verification identifier |
identifier | text | Not Null | User identifier (email, phone, etc.) |
value | text | Not Null | Verification token/code |
expiresAt | timestamp | Not Null | Token expiration time |
createdAt | timestamp | Auto | Token creation time |
updatedAt | timestamp | Auto | Last update time |
JWKS Table
Stores JSON Web Key Sets for JWT token verification.src/db/schema.ts
| Column | Type | Constraints | Description |
|---|---|---|---|
id | text | Primary Key | Unique key identifier |
publicKey | text | Not Null | Public key (for JWT verification) |
privateKey | text | Not Null | Private key (for JWT signing) |
createdAt | timestamp | Not Null | Key creation timestamp |
The JWKS table is used by Better Auth to issue and verify JWTs. Your backend can fetch public keys from the
/api/auth/jwks endpoint to verify tokens without sharing secrets.Schema Relationships
The schema includes the following relationships:Type Inference
Drizzle automatically infers TypeScript types from your schema:Extending the Schema
To add custom tables to the schema, see the Adding Tables guide.Next Steps
Migrations
Learn how to apply schema changes
Adding Tables
Add custom tables to your database