Add purpose column to magic_tokens, fix email change race condition
- Add `purpose` column (default: 'login') to distinguish login tokens from email-change tokens - verifyMagicToken only matches purpose='login' - verifyEmailChange only matches purpose='email-change' - Re-check email availability at verification time, not just initiation — prevents race where someone registers with the new email between request and verification Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
715b272395
commit
a766bffad5
2 changed files with 14 additions and 8 deletions
|
|
@ -49,6 +49,7 @@ export const magicTokens = journalSchema.table("magic_tokens", {
|
|||
id: text("id").primaryKey(),
|
||||
email: text("email").notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
purpose: text("purpose").notNull().default("login"),
|
||||
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
||||
usedAt: timestamp("used_at", { withTimezone: true }),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue