Skip to content

Fix: cloneResponse breaks onError hook#79

Open
leo91000 wants to merge 1 commit intobetter-auth:mainfrom
leo91000:fix/clone-response-error
Open

Fix: cloneResponse breaks onError hook#79
leo91000 wants to merge 1 commit intobetter-auth:mainfrom
leo91000:fix/clone-response-error

Conversation

@leo91000
Copy link
Copy Markdown

Fixes #74

When hookOptions: { cloneResponse: true } is set, error responses now work correctly.

Root cause: response.text() was called before response.clone(), consuming the body.

Fix: Clone before consuming in the error branch.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

When cloneResponse option is enabled, clone the response before calling

response.text() so the original response can still be cloned for hooks.

Fixes better-auth#74
@leo91000 leo91000 force-pushed the fix/clone-response-error branch from a17764e to da00381 Compare March 2, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloneResponse: true breaks onError hook - "Body has already been consumed"

2 participants