Skip to content

Commit db440bf

Browse files
Claudehotlong
andauthored
fix(auth): handle /api/v1/auth/config endpoint in Hono adapter
- Handle /auth/config endpoint before forwarding to better-auth - Remove duplicate route registration from AuthPlugin to avoid conflicts - Update test expectations for getPublicConfig() type field Fixes: Vercel deployment 404 error for /api/v1/auth/config Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/47d028d7-dd4e-44b3-a99b-226e4322a548 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2493e02 commit db440bf

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

packages/adapters/hono/src/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ export function createHonoApp(options: ObjectStackHonoOptions): Hono {
259259
authService = null;
260260
}
261261

262+
// Handle /auth/config endpoint specifically (not handled by better-auth)
263+
if (path === 'config' && method === 'GET' && authService) {
264+
try {
265+
const config = (authService as any).getPublicConfig?.();
266+
if (config) {
267+
return c.json({
268+
success: true,
269+
data: config,
270+
});
271+
}
272+
} catch (error) {
273+
const err = error instanceof Error ? error : new Error(String(error));
274+
return c.json({
275+
success: false,
276+
error: {
277+
code: 'auth_config_error',
278+
message: err.message,
279+
},
280+
}, 500);
281+
}
282+
}
283+
262284
if (authService && typeof authService.handleRequest === 'function') {
263285
const response = await authService.handleRequest(c.req.raw);
264286
return new Response(response.body, {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,13 @@ describe('AuthManager', () => {
815815
id: 'google',
816816
name: 'Google',
817817
enabled: true,
818+
type: 'social',
818819
});
819820
expect(config.socialProviders[1]).toEqual({
820821
id: 'github',
821822
name: 'GitHub',
822823
enabled: true,
824+
type: 'social',
823825
});
824826

825827
// Should NOT include sensitive data
@@ -899,6 +901,7 @@ describe('AuthManager', () => {
899901
id: 'customProvider',
900902
name: 'CustomProvider',
901903
enabled: true,
904+
type: 'social',
902905
});
903906
});
904907
});

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -246,27 +246,11 @@ export class AuthPlugin implements Plugin {
246246

247247
const rawApp = (httpServer as any).getRawApp();
248248

249-
// Register auth config endpoint - public endpoint for frontend discovery
250-
rawApp.get(`${basePath}/config`, async (c: any) => {
251-
try {
252-
const config = this.authManager!.getPublicConfig();
253-
return c.json({
254-
success: true,
255-
data: config,
256-
});
257-
} catch (error) {
258-
const err = error instanceof Error ? error : new Error(String(error));
259-
ctx.logger.error('Auth config error:', err);
260-
261-
return c.json({
262-
success: false,
263-
error: {
264-
code: 'auth_config_error',
265-
message: err.message,
266-
},
267-
}, 500);
268-
}
269-
});
249+
// NOTE: The `/config` endpoint is now handled in the Hono adapter itself
250+
// (packages/adapters/hono/src/index.ts) to avoid route ordering conflicts.
251+
// The adapter's catch-all `/auth/*` route intercepts all auth requests
252+
// before plugin routes can be registered, so we check for `/config` there
253+
// and call getPublicConfig() directly on the auth service.
270254

271255
// Register wildcard route to forward all auth requests to better-auth.
272256
// better-auth is configured with basePath matching our route prefix, so we

0 commit comments

Comments
 (0)