[GH-ISSUE #6636] [1.4.6] ExpressJS and toNodeHandler gives 404 errors for all paths #19208

Open
opened 2026-04-15 18:02:16 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @vespasianvs on GitHub (Dec 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6636

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

We've been using better-auth for a while with our ExpressJS backend with no issues. I've just tried to update from 1.4.4 to 1.4.6 and all of the routes seem to break.

  1. Setup the backend as per the docs for ExpressJS
    app.all("/auth/{*splat}", toNodeHandler(auth));
  2. Try to call the better-auth endpoints, e.g. /auth/get-session

Current vs. Expected behavior

I just get an HTTP 404 for every better-auth route. I haven't changed anything code-wise (and I wouldn't expect to need to for a patch update).

I would expect the routes to still work as they did before.

What version of Better Auth are you using?

1.4.6

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26220",
    "cpuCount": 16,
    "cpuModel": "Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz",
    "totalMemory": "31.92 GB",
    "freeMemory": "12.29 GB"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "express",
      "version": "^5.2.1"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.6",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

{
		appName: "event-app",
		trustedOrigins: [
			***
		],
		database: mongodbAdapter(db),
		logger: console,
		baseURL: new URL("auth/", process.env.BETTER_AUTH_URL ?? "http://localhost:9000").href,
		emailAndPassword: {
			enabled: !isTest
		},
		socialProviders,
		user: {
			// default model name is user, change to users to avoid conflict with mongoose
			modelName: "users",
			additionalFields: {
				role: {
					type: "string",
					input: false
				}
			}
		},
		plugins: [
			admin(),
			organization({
				async sendInvitationEmail(data, request) {
					const origin = request?.headers.get("origin");
					const inviteLink = ***;
					await sendOrganizationInvite({
						senderName: data.inviter.user.name,
						organizationName: data.organization.name,
						appUrl: origin,
						inviteLink,
						email: data.email
					});
				}
			}),
			emailOTP({
				async sendVerificationOTP({ email, otp }) {
					await sendOTPEmail({
						email,
						code: otp
					});
				},
				expiresIn: 600 // Ten mins
			})
		],
		advanced: {
			useSecureCookies: !isTest
		},
	}

Additional context

The outputs above are running on my Windows machine - I have also tried it on our servers and have the same issue.

Originally created by @vespasianvs on GitHub (Dec 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6636 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce We've been using better-auth for a while with our ExpressJS backend with no issues. I've just tried to update from 1.4.4 to 1.4.6 and all of the routes seem to break. 1. Setup the backend as per the docs for ExpressJS `app.all("/auth/{*splat}", toNodeHandler(auth));` 3. Try to call the better-auth endpoints, e.g. /auth/get-session ### Current vs. Expected behavior I just get an HTTP 404 for every better-auth route. I haven't changed anything code-wise (and I wouldn't expect to need to for a patch update). I would expect the routes to still work as they did before. ### What version of Better Auth are you using? 1.4.6 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26220", "cpuCount": 16, "cpuModel": "Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz", "totalMemory": "31.92 GB", "freeMemory": "12.29 GB" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "express", "version": "^5.2.1" } ], "databases": null, "betterAuth": { "version": "^1.4.6", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript { appName: "event-app", trustedOrigins: [ *** ], database: mongodbAdapter(db), logger: console, baseURL: new URL("auth/", process.env.BETTER_AUTH_URL ?? "http://localhost:9000").href, emailAndPassword: { enabled: !isTest }, socialProviders, user: { // default model name is user, change to users to avoid conflict with mongoose modelName: "users", additionalFields: { role: { type: "string", input: false } } }, plugins: [ admin(), organization({ async sendInvitationEmail(data, request) { const origin = request?.headers.get("origin"); const inviteLink = ***; await sendOrganizationInvite({ senderName: data.inviter.user.name, organizationName: data.organization.name, appUrl: origin, inviteLink, email: data.email }); } }), emailOTP({ async sendVerificationOTP({ email, otp }) { await sendOTPEmail({ email, code: otp }); }, expiresIn: 600 // Ten mins }) ], advanced: { useSecureCookies: !isTest }, } ``` ### Additional context The outputs above are running on my Windows machine - I have also tried it on our servers and have the same issue.
GiteaMirror added the platformregressioncorebug labels 2026-04-15 18:02:16 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 9, 2025):

(tag @better-auth-agent if you would like an answer from the Agent)

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3632276175 --> @better-auth-agent[bot] commented on GitHub (Dec 9, 2025): (tag @better-auth-agent if you would like an answer from the Agent) _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 9, 2025):

Hi @vespasianvs! I'm Dosu and I’m helping the better-auth team.

This is a common issue with Express v5 and better-auth. The root cause is usually a mismatch between the route pattern where you mount the handler and the baseURL configured in better-auth, especially after changes in Express v5's wildcard syntax and path matching.

For Express v5, you should use the named wildcard syntax:

app.all('/auth/*splat', toNodeHandler(auth));

not /auth/{*splat} or /auth/*. The {*splat} syntax is not recognized by Express v5's path-to-regexp router—use *splat or *any instead. See the official docs.

Also, make sure:

  • The route you mount matches the baseURL in your better-auth config, including any prefixes from proxies or subrouters. If you use a reverse proxy or subrouter, Express may strip part of the path before passing the request to better-auth, causing 404s. In that case, mount the handler at the full path or use middleware to rewrite req.url to add the missing prefix (details).
  • Mount the better-auth handler before any body parsing middleware like express.json() or bodyParser, otherwise requests can be intercepted and return 404s or hang (docs).
  • The implementation of toNodeHandler itself hasn't changed in a way that would cause this issue; it's just a thin wrapper (source).

If you update your route to use the correct wildcard and ensure the baseURL matches the mount path, your endpoints should work again. If you use subrouters or a proxy, double-check that the full path is preserved and matches the baseURL (example).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3632299960 --> @dosubot[bot] commented on GitHub (Dec 9, 2025): <!-- Greeting --> Hi @vespasianvs! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a common issue with Express v5 and better-auth. The root cause is usually a mismatch between the route pattern where you mount the handler and the baseURL configured in better-auth, especially after changes in Express v5's wildcard syntax and path matching. For Express v5, you should use the named wildcard syntax: ```js app.all('/auth/*splat', toNodeHandler(auth)); ``` not `/auth/{*splat}` or `/auth/*`. The `{*splat}` syntax is not recognized by Express v5's path-to-regexp router—use `*splat` or `*any` instead. See the [official docs](https://github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx#L16-L35). Also, make sure: - The route you mount matches the baseURL in your better-auth config, including any prefixes from proxies or subrouters. If you use a reverse proxy or subrouter, Express may strip part of the path before passing the request to better-auth, causing 404s. In that case, mount the handler at the full path or use middleware to rewrite `req.url` to add the missing prefix ([details](https://github.com/better-auth/better-auth/issues/3887)). - Mount the better-auth handler before any body parsing middleware like `express.json()` or `bodyParser`, otherwise requests can be intercepted and return 404s or hang ([docs](https://github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx#L16-L35)). - The implementation of `toNodeHandler` itself hasn't changed in a way that would cause this issue; it's just a thin wrapper ([source](https://github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/packages/better-auth/src/integrations/node.ts#L2-L13)). If you update your route to use the correct wildcard and ensure the baseURL matches the mount path, your endpoints should work again. If you use subrouters or a proxy, double-check that the full path is preserved and matches the baseURL ([example](https://github.com/better-auth/better-auth/issues/3215)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/577a7534-8dec-4bb8-aa8f-d140beb50d4a?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20common%20issue%20with%20Express%20v5%20and%20better-auth.%20The%20root%20cause%20is%20usually%20a%20mismatch%20between%20the%20route%20pattern%20where%20you%20mount%20the%20handler%20and%20the%20baseURL%20configured%20in%20better-auth%2C%20especially%20after%20changes%20in%20Express%20v5%27s%20wildcard%20syntax%20and%20path%20matching.%0A%0AFor%20Express%20v5%2C%20you%20should%20use%20the%20named%20wildcard%20syntax%3A%20%20%0A%60%60%60js%0Aapp.all%28%27/auth/%2Asplat%27%2C%20toNodeHandler%28auth%29%29%3B%0A%60%60%60%0Anot%20%60/auth/%7B%2Asplat%7D%60%20or%20%60/auth/%2A%60.%20The%20%60%7B%2Asplat%7D%60%20syntax%20is%20not%20recognized%20by%20Express%20v5%27s%20path-to-regexp%20router%E2%80%94use%20%60%2Asplat%60%20or%20%60%2Aany%60%20instead.%20See%20the%20%5Bofficial%20docs%5D%28https%3A//github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx%23L16-L35%29.%0A%0AAlso%2C%20make%20sure%3A%0A-%20The%20route%20you%20mount%20matches%20the%20baseURL%20in%20your%20better-auth%20config%2C%20including%20any%20prefixes%20from%20proxies%20or%20subrouters.%20If%20you%20use%20a%20reverse%20proxy%20or%20subrouter%2C%20Express%20may%20strip%20part%20of%20the%20path%20before%20passing%20the%20request%20to%20better-auth%2C%20causing%20404s.%20In%20that%20case%2C%20mount%20the%20handler%20at%20the%20full%20path%20or%20use%20middleware%20to%20rewrite%20%60req.url%60%20to%20add%20the%20missing%20prefix%20%28%5Bdetails%5D%28https%3A//github.com/better-auth/better-auth/issues/3887%29%29.%0A-%20Mount%20the%20better-auth%20handler%20before%20any%20body%20parsing%20middleware%20like%20%60express.json%28%29%60%20or%20%60bodyParser%60%2C%20otherwise%20requests%20can%20be%20intercepted%20and%20return%20404s%20or%20hang%20%28%5Bdocs%5D%28https%3A//github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx%23L16-L35%29%29.%0A-%20The%20implementation%20of%20%60toNodeHandler%60%20itself%20hasn%27t%20changed%20in%20a%20way%20that%20would%20cause%20this%20issue%3B%20it%27s%20just%20a%20thin%20wrapper%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/packages/better-auth/src/integrations/node.ts%23L2-L13%29%29.%0A%0AIf%20you%20update%20your%20route%20to%20use%20the%20correct%20wildcard%20and%20ensure%20the%20baseURL%20matches%20the%20mount%20path%2C%20your%20endpoints%20should%20work%20again.%20If%20you%20use%20subrouters%20or%20a%20proxy%2C%20double-check%20that%20the%20full%20path%20is%20preserved%20and%20matches%20the%20baseURL%20%28%5Bexample%5D%28https%3A//github.com/better-auth/better-auth/issues/3215%29%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6636)
Author
Owner

@vespasianvs commented on GitHub (Dec 9, 2025):

@dosu I haven't changed my setup since upgrading from 1.4.4 - it has been working well. Just the step of upgrading from 1.4.4 to 1.4.6 seems to break the routes, so something has changed somewhere. My route does match my baseURL and the better-auth handler is called before any other middleware.

<!-- gh-comment-id:3632738009 --> @vespasianvs commented on GitHub (Dec 9, 2025): @dosu I haven't changed my setup since upgrading from 1.4.4 - it has been working well. Just the step of upgrading from 1.4.4 to 1.4.6 seems to break the routes, so something has changed somewhere. My route does match my baseURL and the better-auth handler is called before any other middleware.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 9, 2025):

There are no breaking changes in better-auth core or toNodeHandler between 1.4.4 and 1.4.6, but Express v5's route matching is very strict about wildcard syntax. For Express v5, the correct pattern is app.all('/auth/*splat', toNodeHandler(auth));—not /auth/{*splat} or /auth/*—as documented in the latest integration guide. Using the wrong pattern can cause all routes to return 404s, even if it worked in earlier versions or with different Express versions. See the official docs.

If you’re already using the correct pattern and still seeing 404s, try deleting node_modules and doing a clean install to ensure all dependencies (like better-call) are up to date, as there was a known issue with subrouter path handling that was fixed in a recent better-call release. If you use subrouters or a proxy, make sure the full path (including any prefixes) matches your baseURL, or use middleware to rewrite req.url before the handler if needed see discussion.

If you’re still stuck after these checks, feel free to share your exact route and config for a closer look.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3632762483 --> @dosubot[bot] commented on GitHub (Dec 9, 2025): <!-- Answer --> There are no breaking changes in better-auth core or toNodeHandler between 1.4.4 and 1.4.6, but Express v5's route matching is very strict about wildcard syntax. For Express v5, the correct pattern is `app.all('/auth/*splat', toNodeHandler(auth));`—not `/auth/{*splat}` or `/auth/*`—as documented in the latest integration guide. Using the wrong pattern can cause all routes to return 404s, even if it worked in earlier versions or with different Express versions. See the [official docs](https://github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx#L16-L40). If you’re already using the correct pattern and still seeing 404s, try deleting node_modules and doing a clean install to ensure all dependencies (like better-call) are up to date, as there was a known issue with subrouter path handling that was fixed in a recent better-call release. If you use subrouters or a proxy, make sure the full path (including any prefixes) matches your baseURL, or use middleware to rewrite req.url before the handler if needed [see discussion](https://github.com/better-auth/better-auth/issues/3887). If you’re still stuck after these checks, feel free to share your exact route and config for a closer look. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4dc60cfe-14b8-4d6b-a5b4-9b507d3d6fda?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=There%20are%20no%20breaking%20changes%20in%20better-auth%20core%20or%20toNodeHandler%20between%201.4.4%20and%201.4.6%2C%20but%20Express%20v5%27s%20route%20matching%20is%20very%20strict%20about%20wildcard%20syntax.%20For%20Express%20v5%2C%20the%20correct%20pattern%20is%20%60app.all%28%27/auth/%2Asplat%27%2C%20toNodeHandler%28auth%29%29%3B%60%E2%80%94not%20%60/auth/%7B%2Asplat%7D%60%20or%20%60/auth/%2A%60%E2%80%94as%20documented%20in%20the%20latest%20integration%20guide.%20Using%20the%20wrong%20pattern%20can%20cause%20all%20routes%20to%20return%20404s%2C%20even%20if%20it%20worked%20in%20earlier%20versions%20or%20with%20different%20Express%20versions.%20See%20the%20%5Bofficial%20docs%5D%28https%3A//github.com/better-auth/better-auth/blob/c3fe979cb51c127dd7b68413937a0c04fc3f6526/docs/content/docs/integrations/express.mdx%23L16-L40%29.%0A%0AIf%20you%E2%80%99re%20already%20using%20the%20correct%20pattern%20and%20still%20seeing%20404s%2C%20try%20deleting%20node_modules%20and%20doing%20a%20clean%20install%20to%20ensure%20all%20dependencies%20%28like%20better-call%29%20are%20up%20to%20date%2C%20as%20there%20was%20a%20known%20issue%20with%20subrouter%20path%20handling%20that%20was%20fixed%20in%20a%20recent%20better-call%20release.%20If%20you%20use%20subrouters%20or%20a%20proxy%2C%20make%20sure%20the%20full%20path%20%28including%20any%20prefixes%29%20matches%20your%20baseURL%2C%20or%20use%20middleware%20to%20rewrite%20req.url%20before%20the%20handler%20if%20needed%20%5Bsee%20discussion%5D%28https%3A//github.com/better-auth/better-auth/issues/3887%29.%0A%0AIf%20you%E2%80%99re%20still%20stuck%20after%20these%20checks%2C%20feel%20free%20to%20share%20your%20exact%20route%20and%20config%20for%20a%20closer%20look.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6636)
Author
Owner

@vespasianvs commented on GitHub (Dec 9, 2025):

@dosu I tried changing the route to: app.all("/auth/*splat", toNodeHandler(auth));

I also did a clean install of node_modules. The issue still occurs. The only 'fix' that I have found so far is to roll back better-auth to 1.4.4

<!-- gh-comment-id:3632822854 --> @vespasianvs commented on GitHub (Dec 9, 2025): @dosu I tried changing the route to: `app.all("/auth/*splat", toNodeHandler(auth));` I also did a clean install of node_modules. The issue still occurs. The only 'fix' that I have found so far is to roll back better-auth to 1.4.4
Author
Owner

@emanueldev1 commented on GitHub (Dec 11, 2025):

+1, using it on nestjs, all routes have the 404 raw error...

Rollback to 1.4.5 it works for me.

<!-- gh-comment-id:3643337710 --> @emanueldev1 commented on GitHub (Dec 11, 2025): +1, using it on nestjs, all routes have the 404 raw error... Rollback to 1.4.5 it works for me.
Author
Owner

@yacjne commented on GitHub (Dec 12, 2025):

Hello,

In nestjs, I fixed the 404 issue (with 1.4.6) by adding the following code in main.ts:

// main.ts
const express = app.getHttpAdapter().getInstance();
express.all(/^\/api\/auth\/.*$/, toNodeHandler(auth));

this could also work for Express

<!-- gh-comment-id:3645925612 --> @yacjne commented on GitHub (Dec 12, 2025): Hello, In nestjs, I fixed the 404 issue (with 1.4.6) by adding the following code in `main.ts`: ```typescript // main.ts const express = app.getHttpAdapter().getInstance(); express.all(/^\/api\/auth\/.*$/, toNodeHandler(auth)); ``` this could also work for Express
Author
Owner

@emanueldev1 commented on GitHub (Dec 12, 2025):

Hello,

In nestjs, I fixed the 404 issue (with 1.4.6) by adding the following code in main.ts:

// main.ts
const express = app.getHttpAdapter().getInstance();
express.all(/^/api/auth/.*$/, toNodeHandler(auth));
this could also work for Express

@yacjne it works perfectly, thanks i im using it on nestjs and it works,

NestJS

const handler = toNodeHandler(this.options.auth);
    this.adapter.httpAdapter
      .getInstance()
      // little hack to ignore any global prefix
      // for now i'll just not support a global prefix
      .use(`${basePath}/*path`, (req: Request, res: Response) => {
        return handler(req, res);
      });

Fix Nestjs (disables the custom path basePath buts still modificable in the regex of the fix code.)

      const handler = toNodeHandler(this.options.auth);
      this.adapter.httpAdapter
      .getInstance()
      .all(/^\/api\/auth\/.*$/, (req: Request, res: Response) => {
        return handler(req, res);
      });
<!-- gh-comment-id:3646895750 --> @emanueldev1 commented on GitHub (Dec 12, 2025): > Hello, > > In nestjs, I fixed the 404 issue (with 1.4.6) by adding the following code in `main.ts`: > > // main.ts > const express = app.getHttpAdapter().getInstance(); > express.all(/^\/api\/auth\/.*$/, toNodeHandler(auth)); > this could also work for Express @yacjne it works perfectly, thanks i im using it on nestjs and it works, NestJS ```ts const handler = toNodeHandler(this.options.auth); this.adapter.httpAdapter .getInstance() // little hack to ignore any global prefix // for now i'll just not support a global prefix .use(`${basePath}/*path`, (req: Request, res: Response) => { return handler(req, res); }); ``` Fix Nestjs (disables the custom path basePath buts still modificable in the regex of the fix code.) ```ts const handler = toNodeHandler(this.options.auth); this.adapter.httpAdapter .getInstance() .all(/^\/api\/auth\/.*$/, (req: Request, res: Response) => { return handler(req, res); }); ```
Author
Owner

@haike0513 commented on GitHub (Dec 12, 2025):

When I use Vike+hono, the route /api/auth/session not found.

const app = new Hono(); 
app.all("/api/auth/*", async (c) => {
    console.log("authHandler", c.req.path);
    const response = await authHandler(c.req.raw);
    return response;
  });

the request is success pass to authHandler. But the result of response is 404
/api/auth/sign-in/email can be handle success

<!-- gh-comment-id:3647955372 --> @haike0513 commented on GitHub (Dec 12, 2025): When I use Vike+hono, the route `/api/auth/session` not found. ```javascript const app = new Hono(); app.all("/api/auth/*", async (c) => { console.log("authHandler", c.req.path); const response = await authHandler(c.req.raw); return response; }); ``` the request is success pass to authHandler. But the result of response is 404 `/api/auth/sign-in/email` can be handle success
Author
Owner

@maxdevos49 commented on GitHub (Dec 31, 2025):

Made a PR for this issue in better-call: https://github.com/better-auth/better-call/pull/93

Issue seems to be the request url is constructed incorrectly for middleware wildcard endpoints and some subrouter endpoints.

<!-- gh-comment-id:3702740684 --> @maxdevos49 commented on GitHub (Dec 31, 2025): Made a PR for this issue in better-call: https://github.com/better-auth/better-call/pull/93 Issue seems to be the request url is constructed incorrectly for middleware wildcard endpoints and some subrouter endpoints.
Author
Owner

@Mellywins commented on GitHub (Feb 1, 2026):

This is still happening with 1.4.18

<!-- gh-comment-id:3831175945 --> @Mellywins commented on GitHub (Feb 1, 2026): This is still happening with 1.4.18
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19208