@@ -181,30 +181,13 @@ export class AuthPlugin implements Plugin {
181181
182182 const rawApp = ( httpServer as any ) . getRawApp ( ) ;
183183
184- // Register wildcard route to forward all auth requests to better-auth
185- // Better-auth expects requests at its baseURL, so we need to preserve the full path
184+ // Register wildcard route to forward all auth requests to better-auth.
185+ // better-auth is configured with basePath matching our route prefix, so we
186+ // forward the original request directly — no path rewriting needed.
186187 rawApp . all ( `${ basePath } /*` , async ( c : any ) => {
187188 try {
188- // Get the Web standard Request from Hono context
189- const request = c . req . raw as Request ;
190-
191- // Create a new Request with the path rewritten to match better-auth's expectations
192- // Better-auth expects paths like /sign-in/email, /sign-up/email, etc.
193- // We need to strip our basePath prefix
194- const url = new URL ( request . url ) ;
195- const authPath = url . pathname . replace ( basePath , '' ) ;
196- const rewrittenUrl = new URL ( authPath || '/' , url . origin ) ;
197- rewrittenUrl . search = url . search ; // Preserve query params
198-
199- const rewrittenRequest = new Request ( rewrittenUrl , {
200- method : request . method ,
201- headers : request . headers ,
202- body : request . body ,
203- duplex : 'half' as any , // Required for Request with body
204- } ) ;
205-
206- // Forward to better-auth handler
207- const response = await this . authManager ! . handleRequest ( rewrittenRequest ) ;
189+ // Forward the original request to better-auth handler
190+ const response = await this . authManager ! . handleRequest ( c . req . raw ) ;
208191
209192 // better-auth catches internal errors and returns error Responses
210193 // without throwing, so the catch block below would never trigger.
0 commit comments