Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Set basePath to '/api/v1/auth' (configurable) in auth-manager.ts instead of '/' - Remove manual URL rewriting in auth-plugin.ts, forward c.req.raw directly - Add basePath to AuthManagerOptions interface - Add tests for basePath configuration Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor AuthPlugin to align with better-auth best practices
Refactor AuthPlugin to align with better-auth best practices (basePath, handler forwarding)
Mar 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the AuthPlugin and AuthManager to align with better-auth's proper integration model. Previously, AuthManager set basePath: '/' and AuthPlugin compensated by manually rewriting request URLs (stripping the API prefix), which was fragile and broke better-auth's path matching assumptions. The fix correctly configures better-auth's basePath to match the actual route prefix and removes the unnecessary URL rewriting.
Changes:
AuthManager.createAuthInstance()now usesthis.config.basePath || '/api/v1/auth'instead of the hardcoded'/', andbasePathis added as a documented field inAuthManagerOptions.AuthPlugin.registerAuthRoutes()removes 13 lines of URL rewriting (stripping prefix, reconstructingRequest, usingduplex: 'half') and replaces them with a single directthis.authManager!.handleRequest(c.req.raw)call.- Two new tests in
auth-manager.test.tsverify thatbasePathdefaults correctly and accepts custom values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/plugins/plugin-auth/src/auth-manager.ts |
Adds basePath field to AuthManagerOptions with @default '/api/v1/auth'; changes basePath in betterAuth config from hardcoded '/' to this.config.basePath || '/api/v1/auth' |
packages/plugins/plugin-auth/src/auth-plugin.ts |
Removes manual URL rewriting; forwards c.req.raw directly to handleRequest; updates route registration comment |
packages/plugins/plugin-auth/src/auth-manager.test.ts |
Adds basePath configuration test suite with two tests verifying default and custom basePath behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AuthManagerhardcodedbasePath: '/'andAuthPlugincompensated by manually rewriting request URLs (stripping the prefix, reconstructing a newRequestwithduplex: 'half'). This breaks better-auth's assumptions about path matching and is fragile.Changes
auth-manager.ts: SetbasePathtothis.config.basePath || '/api/v1/auth'instead of'/'. AddedbasePathtoAuthManagerOptions.auth-plugin.ts: Removed 13 lines of URL rewriting. Route handler now forwards directly:auth-manager.test.ts: Added tests verifyingbasePathdefaults correctly and accepts custom values.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.