mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Implement self-hosted MCP server for admin actions, update AI generation tools in admin dashboard, and refine mobile app stores and components.
26 lines
806 B
TypeScript
26 lines
806 B
TypeScript
import { Context, Next } from 'hono';
|
|
|
|
export const authMiddleware = async (c: Context, next: Next) => {
|
|
const authHeader = c.req.header('Authorization');
|
|
const apiKey = process.env.SAUCI_MCP_API_KEY;
|
|
|
|
if (!apiKey) {
|
|
// If no API key is set in env, allow access (warn in logs)
|
|
// Ideally this should default to deny, but for dev ease we might want to warn
|
|
console.warn('SAUCI_MCP_API_KEY not set in environment - allowing all requests');
|
|
return next();
|
|
}
|
|
|
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
return c.json({ error: 'Unauthorized: Missing or invalid Authorization header' }, 401);
|
|
}
|
|
|
|
const token = authHeader.replace('Bearer ', '');
|
|
|
|
if (token !== apiKey) {
|
|
return c.json({ error: 'Unauthorized: Invalid API key' }, 401);
|
|
}
|
|
|
|
return next();
|
|
};
|