[PR #9045] [CLOSED] fix: clone request before passing to sendVerificationEmail #16645

Closed
opened 2026-04-13 10:37:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9045
Author: @FaryalRizwaan
Created: 4/8/2026
Status: Closed

Base: mainHead: fix/request-body-locked-background-task


📝 Commits (5)

📊 Changes

5 files changed (+114 additions, -16 deletions)

View changed files

📝 landing/app/docs/[[...slug]]/page.client.tsx (+29 -1)
📝 landing/app/docs/[[...slug]]/page.tsx (+1 -0)
📝 packages/better-auth/src/api/routes/email-verification.test.ts (+81 -12)
📝 packages/better-auth/src/api/routes/sign-in.ts (+1 -1)
📝 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 email callbacks to prevent locked-body crashes in background tasks. Also adds a small docs improvement for copying raw MD links. Fixes #8969.

  • Bug Fixes

    • Use ctx.request?.clone() when calling sendVerificationEmail and related email hooks to avoid "Response body object should not be disturbed or locked".
    • Added regression tests in email verification suites to cover this scenario.
  • New Features

    • Docs: Added a "Copy MD Link" button in ViewOptions and passed rawMdUrl to enable easy sharing of the raw markdown URL.

Written for commit 7a8c0a0046. 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/9045 **Author:** [@FaryalRizwaan](https://github.com/FaryalRizwaan) **Created:** 4/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/request-body-locked-background-task` --- ### 📝 Commits (5) - [`d453a7e`](https://github.com/better-auth/better-auth/commit/d453a7ec3af07d0c2e3b1f60fdf52b5d382152b8) feat(docs): add copy MD link button to view options dropdown (#8680) - [`2f6ac2d`](https://github.com/better-auth/better-auth/commit/2f6ac2dd4673785bb44d95b6503f250e6afc3e35) Merge branch 'main' into feat/copy-md-link-button - [`b76eddf`](https://github.com/better-auth/better-auth/commit/b76eddf7d8f7e5c7db512cac90375eb11795d56e) fix: return clipboard promise in CopyMdLinkButton - [`0b067dd`](https://github.com/better-auth/better-auth/commit/0b067dd3af3c0cb3b8b4add50394bb7148bf8b16) Merge branch 'feat/copy-md-link-button' of https://github.com/FaryalRizwaan/better-auth into feat/copy-md-link-button - [`7a8c0a0`](https://github.com/better-auth/better-auth/commit/7a8c0a0046db155bc7d77ba43b30bbcfdd488d47) fix: clone request before passing to sendVerificationEmail ### 📊 Changes **5 files changed** (+114 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `landing/app/docs/[[...slug]]/page.client.tsx` (+29 -1) 📝 `landing/app/docs/[[...slug]]/page.tsx` (+1 -0) 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+81 -12) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+1 -1) 📝 `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 email callbacks to prevent locked-body crashes in background tasks. Also adds a small docs improvement for copying raw MD links. Fixes #8969. - **Bug Fixes** - Use `ctx.request?.clone()` when calling `sendVerificationEmail` and related email hooks to avoid "Response body object should not be disturbed or locked". - Added regression tests in email verification suites to cover this scenario. - **New Features** - Docs: Added a "Copy MD Link" button in `ViewOptions` and passed `rawMdUrl` to enable easy sharing of the raw markdown URL. <sup>Written for commit 7a8c0a0046db155bc7d77ba43b30bbcfdd488d47. 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:37:38 -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#16645