[PR #8247] [MERGED] fix(db): support verification operations with secondary storage #24750

Closed
opened 2026-04-15 22:32:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8247
Author: @himself65
Created: 3/1/2026
Status: Merged
Merged: 3/1/2026
Merged by: @himself65

Base: canaryHead: fix/magic-link-secondary-storage


📝 Commits (3)

  • 466f876 fix(db): support verification CRUD operations with secondary storage
  • 102f6c3 test(magic-link): move secondary storage tests to test/unit/
  • d574d18 refactor(db): remove id-based verification methods, use identifier-based only

📊 Changes

23 files changed (+513 additions, -124 deletions)

View changed files

📝 packages/better-auth/src/api/routes/password.ts (+1 -1)
📝 packages/better-auth/src/api/routes/update-user.ts (+3 -1)
📝 packages/better-auth/src/db/internal-adapter.test.ts (+2 -2)
📝 packages/better-auth/src/db/internal-adapter.ts (+46 -21)
📝 packages/better-auth/src/plugins/email-otp/routes.ts (+30 -29)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+6 -6)
📝 packages/better-auth/src/plugins/mcp/index.ts (+4 -4)
📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+8 -8)
📝 packages/better-auth/src/plugins/one-time-token/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/phone-number/routes.ts (+22 -12)
📝 packages/better-auth/src/plugins/siwe/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/two-factor/otp/index.ts (+6 -6)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+2 -2)
📝 packages/better-auth/src/state.ts (+1 -1)
📝 packages/core/src/types/context.ts (+2 -4)
📝 packages/electron/src/routes.ts (+3 -1)
📝 packages/electron/test/electron.test.ts (+1 -1)
📝 packages/oauth-provider/src/authorize.ts (+4 -9)
📝 packages/oauth-provider/src/token.ts (+3 -3)

...and 3 more files

📄 Description

Summary

Fixes #8228

When secondaryStorage is configured without verification.storeInDatabase, the verification table is excluded from the DB schema by getAuthTables(). This caused deleteVerificationValue(id) and updateVerificationValue(id) to fail with Model "verification" not found in schema because they operate by DB id, which doesn't exist in secondary-only mode.

  • Add updateVerificationByIdentifier to the internal adapter, following the existing deleteVerificationByIdentifier pattern
  • Migrate all callers across the codebase from id-based (deleteVerificationValue/updateVerificationValue) to identifier-based (deleteVerificationByIdentifier/updateVerificationByIdentifier) methods
  • Remove the now-unused id-based methods from the internal adapter and type definitions
  • Handle expiresAt as string when secondary storage returns pre-parsed objects (fixes expiresAt.getTime is not a function)

Affected plugins/modules

magic-link, email-otp, two-factor, phone-number, one-time-token, oidc-provider, mcp, siwe, oauth-provider, electron, sso, state, password, update-user

Test plan

  • New integration tests in test/unit/magic-link-secondary-storage.test.ts covering:
    • Send and verify magic link with secondary storage (string return)
    • Sign up new user via magic link
    • Track attempts and reject when exceeded
    • Delete expired verification on verify
    • Pre-parsed object return (e.g. Redis wrappers)
  • Existing magic-link tests pass (16/16)
  • Internal adapter tests pass (29/29)
  • email-otp tests pass (70/70)
  • two-factor tests pass (34/34)
  • password tests pass (16/16)
  • one-time-token tests pass (13/13)
  • Typecheck passes
  • Lint passes

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8247 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/1/2026 **Status:** ✅ Merged **Merged:** 3/1/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/magic-link-secondary-storage` --- ### 📝 Commits (3) - [`466f876`](https://github.com/better-auth/better-auth/commit/466f876ebd923bcdbb5261775c95591758ab9297) fix(db): support verification CRUD operations with secondary storage - [`102f6c3`](https://github.com/better-auth/better-auth/commit/102f6c35921dadf19f0eff91ce08efba0cd5ce82) test(magic-link): move secondary storage tests to test/unit/ - [`d574d18`](https://github.com/better-auth/better-auth/commit/d574d181a44fcb5032e9424e500dcf444bb4e709) refactor(db): remove id-based verification methods, use identifier-based only ### 📊 Changes **23 files changed** (+513 additions, -124 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/password.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+3 -1) 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+2 -2) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+46 -21) 📝 `packages/better-auth/src/plugins/email-otp/routes.ts` (+30 -29) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+6 -6) 📝 `packages/better-auth/src/plugins/mcp/index.ts` (+4 -4) 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+8 -8) 📝 `packages/better-auth/src/plugins/one-time-token/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/phone-number/routes.ts` (+22 -12) 📝 `packages/better-auth/src/plugins/siwe/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/two-factor/otp/index.ts` (+6 -6) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+2 -2) 📝 `packages/better-auth/src/state.ts` (+1 -1) 📝 `packages/core/src/types/context.ts` (+2 -4) 📝 `packages/electron/src/routes.ts` (+3 -1) 📝 `packages/electron/test/electron.test.ts` (+1 -1) 📝 `packages/oauth-provider/src/authorize.ts` (+4 -9) 📝 `packages/oauth-provider/src/token.ts` (+3 -3) _...and 3 more files_ </details> ### 📄 Description ## Summary Fixes #8228 When `secondaryStorage` is configured without `verification.storeInDatabase`, the verification table is excluded from the DB schema by `getAuthTables()`. This caused `deleteVerificationValue(id)` and `updateVerificationValue(id)` to fail with `Model "verification" not found in schema` because they operate by DB id, which doesn't exist in secondary-only mode. - Add `updateVerificationByIdentifier` to the internal adapter, following the existing `deleteVerificationByIdentifier` pattern - Migrate **all** callers across the codebase from id-based (`deleteVerificationValue`/`updateVerificationValue`) to identifier-based (`deleteVerificationByIdentifier`/`updateVerificationByIdentifier`) methods - Remove the now-unused id-based methods from the internal adapter and type definitions - Handle `expiresAt` as string when secondary storage returns pre-parsed objects (fixes `expiresAt.getTime is not a function`) ### Affected plugins/modules `magic-link`, `email-otp`, `two-factor`, `phone-number`, `one-time-token`, `oidc-provider`, `mcp`, `siwe`, `oauth-provider`, `electron`, `sso`, `state`, `password`, `update-user` ## Test plan - [x] New integration tests in `test/unit/magic-link-secondary-storage.test.ts` covering: - Send and verify magic link with secondary storage (string return) - Sign up new user via magic link - Track attempts and reject when exceeded - Delete expired verification on verify - Pre-parsed object return (e.g. Redis wrappers) - [x] Existing magic-link tests pass (16/16) - [x] Internal adapter tests pass (29/29) - [x] email-otp tests pass (70/70) - [x] two-factor tests pass (34/34) - [x] password tests pass (16/16) - [x] one-time-token tests pass (13/13) - [x] Typecheck passes - [x] Lint passes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:32:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24750