[PR #3334] [CLOSED] fix: Internal adapter findVerificationValue() returns undefined at runtime #30364

Closed
opened 2026-04-17 21:28:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3334
Author: @brandonegg
Created: 7/10/2025
Status: Closed

Base: mainHead: fix/handle-undefined-result-in-find-verification-value


📝 Commits (4)

📊 Changes

2 files changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.test.ts (+1 -1)
📝 packages/better-auth/src/db/internal-adapter.ts (+1 -1)

📄 Description

https://github.com/better-auth/better-auth/pull/389 introduces potential for an error which only is caught in runtime where the return type of findVerificationValue() conflicts with the actual return type of undefined | null | Verification. Previously it looks like this function had used the findOne() db-adapater helper, but moved to findMany(). The findOne() function has logic for handling the undefined case with:

if (!results.length) return null; // length 0 is falsey

This PR adapts findVerificationValue() to utilize this same check as adapter.findOne() to ensure at runtime the return type matches that of typescripts type of Verification | null

Below is an example of code that would have a runtime error not caught by the typescript compiler prior to this fix:

const verification = await ctx.context.internalAdapter.findVerificationValue(
    identifier,
);

// verification has type null | Verification

if (verification === null) { // at Runtime verification can be undefined
    throw new APIError("BAD_REQUEST", {
        code: "INVALID_OTP",
        message: ERROR_CODES.INVALID_OTP,
    });
}

🔄 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/3334 **Author:** [@brandonegg](https://github.com/brandonegg) **Created:** 7/10/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/handle-undefined-result-in-find-verification-value` --- ### 📝 Commits (4) - [`363f5d9`](https://github.com/better-auth/better-auth/commit/363f5d9f80644db11f329cc1f8001a8468b539ee) add check to handle empty result list - [`f77aeb6`](https://github.com/better-auth/better-auth/commit/f77aeb68bc8d8e4b8b64d08f16b8a731d02c9ab4) return null - [`5095355`](https://github.com/better-auth/better-auth/commit/5095355008c7e65839b398e93852f136673ed84d) simplify logic - [`d718054`](https://github.com/better-auth/better-auth/commit/d718054a1d1e11162d08ce97880eeb21f8058bde) add test case to expect null ### 📊 Changes **2 files changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+1 -1) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+1 -1) </details> ### 📄 Description https://github.com/better-auth/better-auth/pull/389 introduces potential for an error which only is caught in runtime where the return type of findVerificationValue() conflicts with the actual return type of `undefined | null | Verification`. Previously it looks like this function had used the `findOne()` db-adapater helper, but moved to `findMany()`. The `findOne()` function has logic for handling the undefined case with: `if (!results.length) return null; // length 0 is falsey` This PR adapts findVerificationValue() to utilize this same check as `adapter.findOne()` to ensure at runtime the return type matches that of typescripts type of `Verification | null` Below is an example of code that would have a runtime error not caught by the typescript compiler prior to this fix: ```ts const verification = await ctx.context.internalAdapter.findVerificationValue( identifier, ); // verification has type null | Verification if (verification === null) { // at Runtime verification can be undefined throw new APIError("BAD_REQUEST", { code: "INVALID_OTP", message: ERROR_CODES.INVALID_OTP, }); } ``` --- <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-17 21:28:56 -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#30364