Skip to content

Commit 676ee76

Browse files
Upgrade Better Auth to 1.7.4 and realign the auth schema (#836)
Better Auth 1.7.3 reverted the account.issuer column that 1.7.0 through 1.7.2 introduced; accounts are keyed on (providerId, accountId) again as in 1.6. Migration 0007 shipped the issuer column as NOT NULL, so on 1.7.3+ every sign-up and account link would fail on that constraint. Migration 0013 drops the unique index first, as the upgrade guide requires, then drops the column. The ORCID accountIssuer option is gone and the OAuth relay carries and looks up the (providerId, accountId) key only. 1.7.3 also validates the drizzle schema on init in every environment and rejects auth requests on a mismatch. That surfaced three twoFactor columns the plugin has expected since 1.7.0 but our table never had: verified, failedVerificationCount and lockedUntil. Production has no two-factor enrolments yet, so nobody hit it, but the first verify would have failed. The same migration adds them. Also in 1.7.3 and 1.7.4: a Cloudflare social provider, isPasswordCompromised for custom flows, a getSession fix when cookie caching is off, and Vitest 5 support in the test utilities. Deploy note: CI migrates before it deploys, so the outgoing 1.7.2 worker runs against the new schema for the length of the deploy. Only sign-ups and account links in that window are affected. Verified: typecheck, lint, shared 332, workers 126, web unit 630, web server 322, web build all pass.
1 parent af5bf75 commit 676ee76

13 files changed

Lines changed: 2083 additions & 101 deletions

File tree

‎packages/db/src/schema.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export const account = sqliteTable(
138138
id: text('id').primaryKey(),
139139
accountId: text('accountId').notNull(),
140140
providerId: text('providerId').notNull(),
141-
issuer: text('issuer').notNull(),
142141
userId: text('userId')
143142
.notNull()
144143
.$type<UserId>()
@@ -153,10 +152,7 @@ export const account = sqliteTable(
153152
createdAt: integer('createdAt', { mode: 'timestamp' }).default(sql`(unixepoch())`),
154153
updatedAt: integer('updatedAt', { mode: 'timestamp' }).default(sql`(unixepoch())`),
155154
},
156-
t => [
157-
index('account_userId_idx').on(t.userId),
158-
uniqueIndex('account_issuer_accountId_uidx').on(t.issuer, t.accountId),
159-
],
155+
t => [index('account_userId_idx').on(t.userId)],
160156
);
161157

162158
// Verification table
@@ -312,6 +308,10 @@ export const twoFactor = sqliteTable('twoFactor', {
312308
.references(() => user.id, { onDelete: 'cascade' }),
313309
secret: text('secret').notNull(),
314310
backupCodes: text('backupCodes').notNull(), // JSON array of backup codes
311+
// Better Auth 1.7 verifies enrolment and locks out repeated failed codes
312+
verified: integer('verified', { mode: 'boolean' }).default(true),
313+
failedVerificationCount: integer('failedVerificationCount').default(0),
314+
lockedUntil: integer('lockedUntil', { mode: 'timestamp' }),
315315
createdAt: integer('createdAt', { mode: 'timestamp' }).default(sql`(unixepoch())`),
316316
updatedAt: integer('updatedAt', { mode: 'timestamp' }).default(sql`(unixepoch())`),
317317
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DROP INDEX `account_issuer_accountId_uidx`;--> statement-breakpoint
2+
ALTER TABLE `account` DROP COLUMN `issuer`;--> statement-breakpoint
3+
ALTER TABLE `twoFactor` ADD `verified` integer DEFAULT true;--> statement-breakpoint
4+
ALTER TABLE `twoFactor` ADD `failedVerificationCount` integer DEFAULT 0;--> statement-breakpoint
5+
ALTER TABLE `twoFactor` ADD `lockedUntil` integer;

0 commit comments

Comments
 (0)