openclaw-dashboard/middleware.ts
AI Assistant c7f037c58a feat: Complete OpenClaw Dashboard with all features
- Dashboard Overview with real-time status display
- Live Log Viewer (scrollable, filterable)
- Config Editor with JSON syntax highlighting
- Model Switcher for provider management
- Provider Manager for API key configuration
- Quick Actions for common tasks
- API Routes: status, logs, config, actions, models, providers

Tech Stack:
- Next.js 14 (App Router)
- TypeScript
- Tailwind CSS
- shadcn/ui components
- CodeMirror for JSON editing
- Docker support with docker-compose
2026-02-27 05:55:23 +00:00

62 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
// Basic Auth configuration
const AUTH_USERNAME = process.env.AUTH_USERNAME || 'admin';
const AUTH_PASSWORD = process.env.AUTH_PASSWORD || 'openclaw';
// Skip auth for public routes (if any)
const publicRoutes = ['/api/status']; // Allow status API without auth for health checks
function basicAuth(req: NextRequest) {
const authHeader = req.headers.get('authorization');
if (!authHeader) {
return false;
}
const [type, credentials] = authHeader.split(' ');
if (type !== 'Basic') {
return false;
}
const decoded = Buffer.from(credentials, 'base64').toString('utf-8');
const [username, password] = decoded.split(':');
return username === AUTH_USERNAME && password === AUTH_PASSWORD;
}
export function middleware(req: NextRequest) {
// Skip auth for public routes
if (publicRoutes.some(route => req.nextUrl.pathname.startsWith(route))) {
return NextResponse.next();
}
if (!basicAuth(req)) {
return new NextResponse(
'Authentication required',
{
status: 401,
headers: {
'WWW-Authenticate': 'Basic realm="OpenClaw Dashboard"',
},
}
);
}
return NextResponse.next();
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!_next/static|_next/image|favicon.ico).*)',
],
};