[GH-ISSUE #72] ElysiaJS Compatibility #16744

Closed
opened 2026-04-15 14:42:38 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @xKesvaL on GitHub (Oct 3, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/72

I love the simplicity and "humanity" of this library and I would love to use it with ElysiaJS but since Elysia is quite different than any express-like framework, it would need its own implementation.

Any plan to do that?

Originally created by @xKesvaL on GitHub (Oct 3, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/72 I love the simplicity and "humanity" of this library and I would love to use it with [ElysiaJS](https://elysiajs.com/) but since Elysia is quite different than any express-like framework, it would need its own implementation. Any plan to do that?
GiteaMirror added the locked label 2026-04-15 14:42:38 -05:00
Author
Owner

@xKesvaL commented on GitHub (Oct 3, 2024):

Current problem is when you pass the request to the handler, it tries accessing the body but Elysia has already parsed it so it will error.
My workaround for now :

.onParse(({ request, route }) => {
    // don't parse body if route is auth
    if (route.startsWith("/api/auth")) {
        return request.body;
    }
})
.all("/api/auth/*", ({ request }) => {
    return auth.handler(request);
});
<!-- gh-comment-id:2390411420 --> @xKesvaL commented on GitHub (Oct 3, 2024): Current problem is when you pass the request to the handler, it tries accessing the body but Elysia has already parsed it so it will error. My workaround for now : ```ts .onParse(({ request, route }) => { // don't parse body if route is auth if (route.startsWith("/api/auth")) { return request.body; } }) .all("/api/auth/*", ({ request }) => { return auth.handler(request); }); ```
Author
Owner

@Bekacru commented on GitHub (Oct 3, 2024):

yeah I'm not familiar with Elysia if you like to make integration, I would love to merge it :))

<!-- gh-comment-id:2392257231 --> @Bekacru commented on GitHub (Oct 3, 2024): yeah I'm not familiar with Elysia if you like to make integration, I would love to merge it :))
Author
Owner

@xKesvaL commented on GitHub (Oct 3, 2024):

Will look into that when I have time! :)

<!-- gh-comment-id:2392455708 --> @xKesvaL commented on GitHub (Oct 3, 2024): Will look into that when I have time! :)
Author
Owner

@Bekacru commented on GitHub (Oct 12, 2024):

#155

<!-- gh-comment-id:2408665550 --> @Bekacru commented on GitHub (Oct 12, 2024): #155
Author
Owner

@yukikwi commented on GitHub (Oct 13, 2024):

Current problem is when you pass the request to the handler, it tries accessing the body but Elysia has already parsed it so it will error. My workaround for now :

.onParse(({ request, route }) => {
    // don't parse body if route is auth
    if (route.startsWith("/api/auth")) {
        return request.body;
    }
})
.all("/api/auth/*", ({ request }) => {
    return auth.handler(request);
});

request.body work for me
image

Code

const betterAuthView = (context: Context) => {
  const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"]
  // validate request method
  if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
    console.log(context.request.url)
    console.log(context.request.body)
    return auth.handler(context.request);
  }
  else {
    context.error(405)
  }
}

const appPrefix = "/api/auth"
const app = new Elysia({ prefix: appPrefix })
  .all("/*", betterAuthView)
<!-- gh-comment-id:2408955046 --> @yukikwi commented on GitHub (Oct 13, 2024): > Current problem is when you pass the request to the handler, it tries accessing the body but Elysia has already parsed it so it will error. My workaround for now : > > ```ts > .onParse(({ request, route }) => { > // don't parse body if route is auth > if (route.startsWith("/api/auth")) { > return request.body; > } > }) > .all("/api/auth/*", ({ request }) => { > return auth.handler(request); > }); > ``` request.body work for me ![image](https://github.com/user-attachments/assets/23324c64-a69c-4fbe-a6af-135170d4f7dc) Code ```ts const betterAuthView = (context: Context) => { const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"] // validate request method if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) { console.log(context.request.url) console.log(context.request.body) return auth.handler(context.request); } else { context.error(405) } } const appPrefix = "/api/auth" const app = new Elysia({ prefix: appPrefix }) .all("/*", betterAuthView) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16744