Skip to content

Commit b596f5a

Browse files
Copilothotlong
andcommitted
Improve type safety with runtime check for getRawApp support
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent e408455 commit b596f5a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/plugins/plugin-auth/src/auth-plugin.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ export class AuthPlugin implements Plugin {
122122
const basePath = this.options.basePath || '/api/v1/auth';
123123

124124
// Get raw Hono app to use native wildcard routing
125-
const rawApp = (httpServer as any).getRawApp?.();
126-
127-
if (!rawApp) {
128-
ctx.logger.error('Cannot access raw HTTP server app - wildcard routing not supported');
129-
throw new Error('HTTP server does not support wildcard routing');
125+
// Type assertion is safe here because we explicitly require Hono server as a dependency
126+
if (!('getRawApp' in httpServer) || typeof (httpServer as any).getRawApp !== 'function') {
127+
ctx.logger.error('HTTP server does not support getRawApp() - wildcard routing requires Hono server');
128+
throw new Error(
129+
'AuthPlugin requires HonoServerPlugin for wildcard routing support. ' +
130+
'Please ensure HonoServerPlugin is loaded before AuthPlugin.'
131+
);
130132
}
131133

134+
const rawApp = (httpServer as any).getRawApp();
135+
132136
// Register wildcard route to forward all auth requests to better-auth
133137
// Better-auth expects requests at its baseURL, so we need to preserve the full path
134138
rawApp.all(`${basePath}/*`, async (c: any) => {

0 commit comments

Comments
 (0)