Elysia "Body already used" #1056

Closed
opened 2026-03-13 08:20:40 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @Lenstack on GitHub (Apr 16, 2025).

To Reproduce

Image

Image

Image

Image

Image

Image

Current vs. Expected behavior

When try to fetch on method POST always the handler response "Body already used" without details.

What version of Better Auth are you using?

v1.2.7

Provide environment information

- OS WINDOWS 11
- BROWSER FIREFOX 137.0.2 (64-bit)

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { magicLink, openAPI } from "better-auth/plugins";
import { surrealAdapter } from "surreal-better-auth";
import { db } from "@/infrastructure/surrealdb/db";

export const betterAuthServer = betterAuth({
    database: surrealAdapter(db),
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID!,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET!
        },
        discord: {
            clientId: process.env.DISCORD_CLIENT_ID!,
            clientSecret: process.env.DISCORD_CLIENT_SECRET!
        }
    },
    plugins: [
        magicLink({
            sendMagicLink({ email, token, url }) {
                console.log("Sending magic link to: ", email);
                console.log("Token: ", token);
                console.log("URL: ", url);
            },
        }),
        openAPI()
    ]
})

Additional context

When try to fetch on method POST always the handler response "Body already used" without details.

Image

Originally created by @Lenstack on GitHub (Apr 16, 2025). ### To Reproduce ![Image](https://github.com/user-attachments/assets/a4361d66-6e40-4368-bfda-e86b79105cf2) ![Image](https://github.com/user-attachments/assets/37ea0e01-8b7d-4bf3-9c4e-ff00cf911b7a) ![Image](https://github.com/user-attachments/assets/61a67099-fba5-4660-96e9-1351664c3607) ![Image](https://github.com/user-attachments/assets/db3e39b8-1532-437c-85d1-a1bc31bc255e) ![Image](https://github.com/user-attachments/assets/15669670-a37c-4bc3-bb17-70c1d4bca506) ![Image](https://github.com/user-attachments/assets/bdbdfa60-50c7-4585-af31-46d52b9638df) ### Current vs. Expected behavior When try to fetch on method POST always the handler response "Body already used" without details. ### What version of Better Auth are you using? v1.2.7 ### Provide environment information ```bash - OS WINDOWS 11 - BROWSER FIREFOX 137.0.2 (64-bit) ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { magicLink, openAPI } from "better-auth/plugins"; import { surrealAdapter } from "surreal-better-auth"; import { db } from "@/infrastructure/surrealdb/db"; export const betterAuthServer = betterAuth({ database: surrealAdapter(db), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET! }, discord: { clientId: process.env.DISCORD_CLIENT_ID!, clientSecret: process.env.DISCORD_CLIENT_SECRET! } }, plugins: [ magicLink({ sendMagicLink({ email, token, url }) { console.log("Sending magic link to: ", email); console.log("Token: ", token); console.log("URL: ", url); }, }), openAPI() ] }) ``` ### Additional context When try to fetch on method POST always the handler response "Body already used" without details. ![Image](https://github.com/user-attachments/assets/a6fff51b-d7c8-40bb-8a4b-e692292d5fd1)
GiteaMirror added the elysiabug labels 2026-03-13 08:20:40 -05:00
Author
Owner

@emirefek commented on GitHub (Apr 18, 2025):

having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem?

@emirefek commented on GitHub (Apr 18, 2025): having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem?
Author
Owner

@Lenstack commented on GitHub (Apr 18, 2025):

having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem?

yeah, i fix using this.

Image

@Lenstack commented on GitHub (Apr 18, 2025): > having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem? yeah, i fix using this. ![Image](https://github.com/user-attachments/assets/76070e9b-5749-47be-bfb4-f2534d2a6b82)
Author
Owner

@vinayakkulkarni commented on GitHub (Apr 19, 2025):

having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem?

yeah, i fix using this.

Image

Can you please share a repro?

@vinayakkulkarni commented on GitHub (Apr 19, 2025): > > having same problem with elysia. Only difference is I am using drizzle adapter. Did you able to fix your problem? > > yeah, i fix using this. > > ![Image](https://github.com/user-attachments/assets/76070e9b-5749-47be-bfb4-f2534d2a6b82) Can you please share a repro?
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

I'm closing as OP has solution.

@ping-maxwell commented on GitHub (Apr 20, 2025): I'm closing as OP has solution.
Author
Owner

@digitalit commented on GitHub (May 6, 2025):

Please reopen this issue. I'm having the same problem. I havent loged in/out for a while and now i get this "Body already used" and i can't figure out how to solve it.

This is my Elysia index.ts:

import {logger} from "@bogeychan/elysia-logger";
import {Elysia} from "elysia";
import cors from "@elysiajs/cors";
import betterAuthView from "@/auth/services/auth.view";
// import wwwRoutes from "@/routes/www";
import adminRoutes from "@/routes/admin";
import {staticPlugin} from '@elysiajs/static'

const app = new Elysia();

app
    .all("api/auth/*", betterAuthView)
    .onRequest(({request}) => {
        if (!request.url.includes('/api/auth/') && !request.url.includes('/public') && !request.url.includes('http://localhost:8091')) {
            //  if (!request.url.includes('/api/auth/') && !request.url.includes('/public')) {
            const apiKey = request.headers.get("x-client-api-key");
            // console.log('request.method', request.method)
            //  console.log('apiKey', apiKey)
            if (!apiKey || (apiKey !== process.env.API_KEY)) {
                if (request.method !== 'OPTIONS') {
                    //  console.log('Unauthorized! Wrong or missing x-client-api-key')
                    throw new Error("Unauthorized");
                }
            }
        }
    })
    .use(logger({
        level: "error",
    }))
    .get('/public', 'Hello from API public')
    .use(
        cors({
            origin: process.env.CORS_DOMAINS ?
                process.env.CORS_DOMAINS.split(',').map(origin => origin.trim()) :
                ['http://localhost:5173'],
            methods: ["GET", "POST", "PATCH", "PUT", "DELETE"],
            credentials: true,
            allowedHeaders: ["Content-Type", "Authorization", "x-client-api-key"],
        }),
    )
    .group("/api", (route) => route.use(adminRoutes))
    .use(staticPlugin())
    .listen(process.env.PORT as string, (server) => {
        console.log(
            `🦊 Elysia Server is running at http://${server?.hostname}:${server?.port}`
        );
    });

Any tip would be much appreciated

@digitalit commented on GitHub (May 6, 2025): Please reopen this issue. I'm having the same problem. I havent loged in/out for a while and now i get this "Body already used" and i can't figure out how to solve it. This is my Elysia index.ts: ``` import {logger} from "@bogeychan/elysia-logger"; import {Elysia} from "elysia"; import cors from "@elysiajs/cors"; import betterAuthView from "@/auth/services/auth.view"; // import wwwRoutes from "@/routes/www"; import adminRoutes from "@/routes/admin"; import {staticPlugin} from '@elysiajs/static' const app = new Elysia(); app .all("api/auth/*", betterAuthView) .onRequest(({request}) => { if (!request.url.includes('/api/auth/') && !request.url.includes('/public') && !request.url.includes('http://localhost:8091')) { // if (!request.url.includes('/api/auth/') && !request.url.includes('/public')) { const apiKey = request.headers.get("x-client-api-key"); // console.log('request.method', request.method) // console.log('apiKey', apiKey) if (!apiKey || (apiKey !== process.env.API_KEY)) { if (request.method !== 'OPTIONS') { // console.log('Unauthorized! Wrong or missing x-client-api-key') throw new Error("Unauthorized"); } } } }) .use(logger({ level: "error", })) .get('/public', 'Hello from API public') .use( cors({ origin: process.env.CORS_DOMAINS ? process.env.CORS_DOMAINS.split(',').map(origin => origin.trim()) : ['http://localhost:5173'], methods: ["GET", "POST", "PATCH", "PUT", "DELETE"], credentials: true, allowedHeaders: ["Content-Type", "Authorization", "x-client-api-key"], }), ) .group("/api", (route) => route.use(adminRoutes)) .use(staticPlugin()) .listen(process.env.PORT as string, (server) => { console.log( `🦊 Elysia Server is running at http://${server?.hostname}:${server?.port}` ); }); ``` Any tip would be much appreciated
Author
Owner

@digitalit commented on GitHub (May 8, 2025):

This was the cause of my problem: https://github.com/bogeychan/elysia-logger/issues/26

@digitalit commented on GitHub (May 8, 2025): This was the cause of my problem: https://github.com/bogeychan/elysia-logger/issues/26
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1056