- API token model (SHA-256 hashed, debounced lastUsedAt) with Bearer auth - Dual auth middleware (session + API token) in src/lib/api-auth.ts - 23 REST endpoints under /api/v1/ covering all functionality: tokens, proxy-hosts, l4-proxy-hosts, certificates, ca-certificates, client-certificates, access-lists, settings, instances, users, audit-log, caddy/apply - OpenAPI 3.1 spec at /api/v1/openapi.json with fully typed schemas - Swagger UI docs page at /api-docs in the dashboard - API token management integrated into the Profile page - Fix: next build now works under Node.js (bun:sqlite aliased to better-sqlite3) - 89 new API route unit tests + 11 integration tests (592 total) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { auth } from "@/src/lib/auth";
|
|
import { NextResponse } from "next/server";
|
|
|
|
/**
|
|
* Next.js Proxy for route protection.
|
|
* Provides defense-in-depth by checking authentication at the edge
|
|
* before requests reach page components.
|
|
*
|
|
* Note: Proxy always runs on Node.js runtime.
|
|
*/
|
|
|
|
export default auth((req) => {
|
|
const isAuthenticated = !!req.auth;
|
|
const pathname = req.nextUrl.pathname;
|
|
|
|
// Allow public routes
|
|
if (
|
|
pathname === "/login" ||
|
|
pathname.startsWith("/api/auth") ||
|
|
pathname === "/api/health" ||
|
|
pathname === "/api/instances/sync" ||
|
|
pathname.startsWith("/api/v1/")
|
|
) {
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Redirect unauthenticated users to login
|
|
if (!isAuthenticated && !pathname.startsWith("/login")) {
|
|
const loginUrl = new URL("/login", req.url);
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
|
|
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)
|
|
* - public folder
|
|
*/
|
|
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
|
|
],
|
|
};
|