feat(proxy): add optional auth for dashboard and API

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vadim Sobinin
2026-03-15 00:23:15 +03:00
parent f8df3ae14b
commit 6bd6a6c8c8
12 changed files with 445 additions and 20 deletions

View File

@@ -0,0 +1,18 @@
import type { MiddlewareHandler } from 'hono';
import { isAuthEnabled } from '../config.js';
import { validateSession } from './sessionStore.js';
export const authMiddleware: MiddlewareHandler = async (c, next) => {
if (!isAuthEnabled()) {
return next();
}
const header = c.req.header('Authorization');
const token = header?.startsWith('Bearer ') ? header.slice(7) : null;
if (!token || !validateSession(token)) {
return c.json({ error: 'Unauthorized' }, 401);
}
return next();
};