twofa schema is missing

SERVER_ERROR: [Error [BetterAuthError]: [# Drizzle Adapter]: The model "twoFactor" was not found in the schema object. Please pass the schema directly to the adapter options.] { cause: undefined } POST /api/auth/two-factor/enable 500 in 987ms
Solution:
had to export it
Jump to solution
7 Replies
david
davidOP3mo ago
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified")
.$defaultFn(() => false)
.notNull(),
image: text("image"),
twoFactorEnabled: boolean("two_factor_enabled").notNull().default(false),
createdAt: timestamp("created_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
updatedAt: timestamp("updated_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
});

export const twoFactor = pgTable("two_factor", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
secret: text("secret").notNull(),
backupCodes: text("backup_codes").notNull(),
});
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified")
.$defaultFn(() => false)
.notNull(),
image: text("image"),
twoFactorEnabled: boolean("two_factor_enabled").notNull().default(false),
createdAt: timestamp("created_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
updatedAt: timestamp("updated_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
});

export const twoFactor = pgTable("two_factor", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
secret: text("secret").notNull(),
backupCodes: text("backup_codes").notNull(),
});
i did npx drizzle-kit push
Solution
david
david3mo ago
had to export it
david
davidOP3mo ago
nvm
Shaki
Shaki2mo ago
I see you have export on the schema. where did you export it to?
david
davidOP2mo ago
in the db/schema.ts file
export const schema = {
...
twoFactor,
...
};
export const schema = {
...
twoFactor,
...
};
Ping
Ping2mo ago
Once the schema is exported (like the code example above ^) you then pass that to the drizzle adapter options in the auth config
Shaki
Shaki2mo ago
I was able to fix it. Thanks

Did you find this page helpful?