fix(proxy): fix auth middleware ordering for Hono
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,12 @@ export const authMiddleware: MiddlewareHandler = async (c, next) => {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip auth for auth routes themselves
|
||||||
|
const path = new URL(c.req.url).pathname;
|
||||||
|
if (path.startsWith('/api/auth')) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
const header = c.req.header('Authorization');
|
const header = c.req.header('Authorization');
|
||||||
const token = header?.startsWith('Bearer ') ? header.slice(7) : null;
|
const token = header?.startsWith('Bearer ') ? header.slice(7) : null;
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ const app = new Hono();
|
|||||||
// CORS for API
|
// CORS for API
|
||||||
app.use('/api/*', corsMiddleware);
|
app.use('/api/*', corsMiddleware);
|
||||||
|
|
||||||
// Auth routes (before auth middleware)
|
// Auth middleware (skips /api/auth/* internally)
|
||||||
app.route('/api/auth', authRoutes);
|
|
||||||
|
|
||||||
// Auth middleware (after auth routes)
|
|
||||||
app.use('/api/*', authMiddleware);
|
app.use('/api/*', authMiddleware);
|
||||||
|
|
||||||
|
// Auth routes
|
||||||
|
app.route('/api/auth', authRoutes);
|
||||||
|
|
||||||
// API routes
|
// API routes
|
||||||
app.route('/api', api);
|
app.route('/api', api);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user