Skip to content

Commit 3035f1b

Browse files
committed
Add Better Auth tables to Drizzle schema
1 parent 29e34f0 commit 3035f1b

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

frontend/lib/auth/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { betterAuth } from "better-auth";
22
import { drizzleAdapter } from "better-auth/adapters/drizzle";
33
import { db } from "@/lib/db";
4+
import * as schema from "@/lib/db/schema";
45

56
export const auth = betterAuth({
67
database: drizzleAdapter(db, {
78
provider: "pg",
9+
schema,
810
}),
911
emailAndPassword: {
1012
enabled: false,

frontend/lib/db/schema.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,58 @@ import {
1111
} from "drizzle-orm/pg-core";
1212
import { relations } from "drizzle-orm";
1313

14-
// Better Auth creates its own tables: user, session, account, verification
15-
// We reference user.id (text) in our app tables
14+
// Better Auth tables
15+
export const user = pgTable("user", {
16+
id: text("id").primaryKey(),
17+
name: text("name").notNull(),
18+
email: text("email").notNull().unique(),
19+
emailVerified: boolean("email_verified").notNull(),
20+
image: text("image"),
21+
createdAt: timestamp("created_at").notNull(),
22+
updatedAt: timestamp("updated_at").notNull(),
23+
});
24+
25+
export const session = pgTable("session", {
26+
id: text("id").primaryKey(),
27+
expiresAt: timestamp("expires_at").notNull(),
28+
token: text("token").notNull().unique(),
29+
createdAt: timestamp("created_at").notNull(),
30+
updatedAt: timestamp("updated_at").notNull(),
31+
ipAddress: text("ip_address"),
32+
userAgent: text("user_agent"),
33+
userId: text("user_id")
34+
.notNull()
35+
.references(() => user.id, { onDelete: "cascade" }),
36+
});
37+
38+
export const account = pgTable("account", {
39+
id: text("id").primaryKey(),
40+
accountId: text("account_id").notNull(),
41+
providerId: text("provider_id").notNull(),
42+
userId: text("user_id")
43+
.notNull()
44+
.references(() => user.id, { onDelete: "cascade" }),
45+
accessToken: text("access_token"),
46+
refreshToken: text("refresh_token"),
47+
idToken: text("id_token"),
48+
accessTokenExpiresAt: timestamp("access_token_expires_at"),
49+
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
50+
scope: text("scope"),
51+
password: text("password"),
52+
createdAt: timestamp("created_at").notNull(),
53+
updatedAt: timestamp("updated_at").notNull(),
54+
});
55+
56+
export const verification = pgTable("verification", {
57+
id: text("id").primaryKey(),
58+
identifier: text("identifier").notNull(),
59+
value: text("value").notNull(),
60+
expiresAt: timestamp("expires_at").notNull(),
61+
createdAt: timestamp("created_at"),
62+
updatedAt: timestamp("updated_at"),
63+
});
64+
65+
// App tables - reference user.id (text)
1666

1767
// Conversations table
1868
export const conversations = pgTable("conversations", {

0 commit comments

Comments
 (0)