Skip to content

fix(node): handle node mount path in Request URL - #32

Merged
Bekacru merged 1 commit into
better-auth:mainfrom
Kinfe123:fix/express-subrouter-url-node-adapter
Aug 9, 2025
Merged

fix(node): handle node mount path in Request URL#32
Bekacru merged 1 commit into
better-auth:mainfrom
Kinfe123:fix/express-subrouter-url-node-adapter

Conversation

@Kinfe123

@Kinfe123 Kinfe123 commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

This PR Fixes 404s when toNodeHandler is used inside an Express subrouter (e.g., mounted under /api). The Node adapter now constructs the full URL using req.baseUrl + req.url when baseUrl is present, preserving the mount path.

Related issue: better-auth/better-auth#3887

When mounted under a subrouter (e.g., /api), Express sets req.url to the route-relative path (e.g., /auth/...) and req.baseUrl to the mount path (e.g., /api). Previously, the adapter built the URL with base + req.url, which dropped the mount path.

before the patch
Screenshot 2025-08-09 at 5 21 24 PM
after the patch

Screenshot 2025-08-09 at 5 22 38 PM

@Bekacru
Bekacru merged commit e131e23 into better-auth:main Aug 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants