[PR #9126] fix: clone request before passing to sendVerificationEmail #16703

Open
opened 2026-04-13 10:39:03 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9126
Author: @FaryalRizwaan
Created: 4/11/2026
Status: 🔄 Open

Base: mainHead: fix/clone-request-email-v2


📝 Commits (4)

  • 0a42b10 fix: clone request before passing to sendVerificationEmail
  • 15e13f4 fix: resolve biome lint warnings in email verification test
  • bb9b07b fix: use const for _capturedToken in test
  • 445d399 fix: formatting in email verification test

📊 Changes

4 files changed (+89 additions, -16 deletions)

View changed files

.changeset/fix-request-clone.md (+5 -0)
📝 packages/better-auth/src/api/routes/email-verification.test.ts (+80 -12)
📝 packages/better-auth/src/api/routes/sign-in.ts (+2 -2)
📝 packages/better-auth/src/api/routes/sign-up.ts (+2 -2)

📄 Description

Problem

ctx.request was passed directly to sendVerificationEmail callbacks after the request body had already been consumed, causing:

TypeError: Response body object should not be disturbed or locked

Fixes #8969

Solution

Use ctx.request?.clone() in all affected places across:

  • email-verification.ts (3 places)
  • sign-up.ts (2 places)
  • sign-in.ts (1 place)

Tests

Added regression tests in both describe blocks to reproduce the bug and confirm the fix works.


Summary by cubic

Clone the incoming request before passing it to emailVerification.sendVerificationEmail and related hooks to avoid locked body errors after the body is read. Fixes email verification failures in sign-up/sign-in flows. Fixes #8969.

  • Bug Fixes
    • Use ctx.request?.clone() when invoking emailVerification.sendVerificationEmail and onExistingUserSignUp in sign-in.ts/sign-up.ts.
    • Add regression tests (standard + secondary storage) to verify request body is readable; fix $Infer.body to socialSignInBodySchema; minor test formatting/lint cleanup.

Written for commit 445d399b79. Summary will update on new commits.


🔄 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/9126 **Author:** [@FaryalRizwaan](https://github.com/FaryalRizwaan) **Created:** 4/11/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/clone-request-email-v2` --- ### 📝 Commits (4) - [`0a42b10`](https://github.com/better-auth/better-auth/commit/0a42b1083a269fd781ef26dbc60a9b0e7eabf629) fix: clone request before passing to sendVerificationEmail - [`15e13f4`](https://github.com/better-auth/better-auth/commit/15e13f497980a276b100ebecfc76abfa1a1a810d) fix: resolve biome lint warnings in email verification test - [`bb9b07b`](https://github.com/better-auth/better-auth/commit/bb9b07b8df67df8c3f608126278b777787ec594f) fix: use const for _capturedToken in test - [`445d399`](https://github.com/better-auth/better-auth/commit/445d399b79f86d51c0f985706465f1047881ad0b) fix: formatting in email verification test ### 📊 Changes **4 files changed** (+89 additions, -16 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/fix-request-clone.md` (+5 -0) 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+80 -12) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+2 -2) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+2 -2) </details> ### 📄 Description ## Problem `ctx.request` was passed directly to `sendVerificationEmail` callbacks after the request body had already been consumed, causing: `TypeError: Response body object should not be disturbed or locked` Fixes #8969 ## Solution Use `ctx.request?.clone()` in all affected places across: - `email-verification.ts` (3 places) - `sign-up.ts` (2 places) - `sign-in.ts` (1 place) ## Tests Added regression tests in both describe blocks to reproduce the bug and confirm the fix works. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Clone the incoming request before passing it to `emailVerification.sendVerificationEmail` and related hooks to avoid locked body errors after the body is read. Fixes email verification failures in sign-up/sign-in flows. Fixes #8969. - **Bug Fixes** - Use `ctx.request?.clone()` when invoking `emailVerification.sendVerificationEmail` and `onExistingUserSignUp` in `sign-in.ts`/`sign-up.ts`. - Add regression tests (standard + secondary storage) to verify request body is readable; fix `$Infer.body` to `socialSignInBodySchema`; minor test formatting/lint cleanup. <sup>Written for commit 445d399b79f86d51c0f985706465f1047881ad0b. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-13 10:39:03 -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#16703