-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@hono/auth-js] don't use request body #783
Conversation
auth-js don't need request body. accessing request body prevent future usage by hono handler
🦋 Changeset detectedLatest commit: 3d02cab The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hi @bordeo Thank you for the PR. @divyam234 Can you review this? |
@bordeo request body is always used in login action middleware/packages/auth-js/src/react.tsx Line 319 in 2d1a89d
|
@divyam234 Thanks! I'll close this PR now. |
I understand your point @divyam234, I'm gonna create a new PR with different approach because if we use |
Are you using bun? |
yes. the problem isn't the runtime but the fact that request body can be used only once |
@bordeo This was added as a workaround for bun as req cloning was not working prior to 1.26 but now this can be replaced by simple request cloning like other runtimes.You can raise pr for that. |
import { test, expect } from "bun:test";
test("should clone request with a readable stream body correctly", async () => {
const originalUrl = "https://example.com";
const clonedUrl = "https://example1.com";
const bodyContent = "test";
const readableStream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(bodyContent));
controller.close();
}
});
const req = new Request(originalUrl, {
method: "POST",
body: readableStream,
headers: {
test: "test"
}
});
const cloneRequest = new Request(clonedUrl, req);
expect(cloneRequest.url).toBe(clonedUrl);
expect(cloneRequest.method).toBe(req.method);
expect(cloneRequest.headers.get("test")).toBe(req.headers.get("test"));
const clonedBody = await cloneRequest.text();
expect(clonedBody).toBe(bodyContent);
}); I had this test in one of my repo which was faling in earlier versions for bun but its passing now on latest version.Took them one year to fix this simple issue |
yes your code is going to work because you are reading the body once with |
#790 this pr will fix this issue |
auth-js don't need request body.
accessing request body prevent future usage by other hono handlers