[PR #396] [MERGED] fix: onRequest callback not interrupting requests #3268

Closed
opened 2026-03-13 10:46:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/396
Author: @0scrm
Created: 11/2/2024
Status: Merged
Merged: 11/7/2024
Merged by: @Bekacru

Base: mainHead: issue-395-on-request-interrupting-not-working


📝 Commits (1)

  • 9d0867a fix: onRequest callback not interrupting requests

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/api/index.ts (+2 -2)

📄 Description

Fixes #395

The response type coming back from plugin.onRequest(req, ctx) is

const response: void | {
    response: Response;
} | {
    request: Request;
}

I suspect that because of that union type, we were returning response although it is not an actual Fetch Response. For this reason, the request was actually not interrupted.

This fix is a pretty simple solution, I also considered using a type guard, let me know what you think :)

function hasResponseInterruptor(response: void | { response: Response } | { request: Request }): response is { response: Response } {
	return response !== undefined && typeof response === 'object' && 'response' in response;
}

🔄 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/396 **Author:** [@0scrm](https://github.com/0scrm) **Created:** 11/2/2024 **Status:** ✅ Merged **Merged:** 11/7/2024 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `issue-395-on-request-interrupting-not-working` --- ### 📝 Commits (1) - [`9d0867a`](https://github.com/better-auth/better-auth/commit/9d0867ac08f2a37e23b5629fede38086db10f972) fix: onRequest callback not interrupting requests ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/index.ts` (+2 -2) </details> ### 📄 Description Fixes #395 The response type coming back from `plugin.onRequest(req, ctx)` is ```ts const response: void | { response: Response; } | { request: Request; } ``` I suspect that because of that union type, we were returning `response` although it is not an actual Fetch Response. For this reason, the request was actually not interrupted. This fix is a pretty simple solution, I also considered using a type guard, let me know what you think :) ```ts function hasResponseInterruptor(response: void | { response: Response } | { request: Request }): response is { response: Response } { return response !== undefined && typeof response === 'object' && 'response' in response; } ``` --- <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-03-13 10:46:16 -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#3268