Skip to content

Elysia.mount(auth.handler) returns 404 for /api/auth/* but works when using explicit GET/POST routes #1806

@pythonhubdev

Description

@pythonhubdev

What version of Elysia is running?

1.4.27

What platform is your computer?

Darwin 25.4.0 arm64 arm

What environment are you using

Bun 1.3.10

Are you using dynamic mode?

No - new Elysia({ aot: true })

What steps can reproduce the bug?

  1. Create a global Elysia app and mount services using the service pattern.
import { Elysia } from "elysia";
import { api } from "./services/api";

const app = new Elysia()
  .use(api)
  .listen(3000);
  1. Create an API service with the /api prefix.
import { Elysia } from "elysia";
import { auth } from "../auth";

export const api = new Elysia({ prefix: "/api" })
  .mount(auth.handler);
  1. Configure Better Auth with:
basePath: "/api/auth"
  1. Start the server.

  2. Call authentication endpoints.

Working endpoints:

POST /api/auth/sign-up/email
POST /api/auth/sign-in/email

These work correctly.

  1. Try accessing the dashboard route:
/api/auth/dash/*

Result:

404 Not Found
  1. If routes are defined explicitly instead of using mount:
export const api = new Elysia({ prefix: "/api" })
  .get("/auth/*", async ({ request }) => auth.handler(request))
  .post("/auth/*", async ({ request }) => auth.handler(request));

Then the dashboard routes work correctly:

/api/auth/dash/*

What is the expected behavior?

Expected behavior

Mounting the Better Auth handler in Elysia should expose all auth routes correctly.

With:

export const api = new Elysia({ prefix: "/api" })
  .mount(auth.handler);

and:

basePath: "/api/auth"

all routes should work, including:

/api/auth/sign-in
/api/auth/sign-up
/api/auth/session
/api/auth/dash/*

The behavior should match the manual routing approach using .get("/auth/*") and .post("/auth/*"), without returning 404 for dashboard routes.

What do you see instead?

18:49:17.107 IST GET /api/auth/dash/list-users      404 Not Found                                                                                                                                                
18:49:17.334 IST GET /api/auth/dash/config          404 Not Found                                                                                                                                                
18:49:16.767 IST GET /api/auth/dash/user-graph-data 404 Not Found

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions