e9c7e9df1a
- tv app/Hobbs-Family-Organizer-Self-Hosted-v1.0.0: release bundle (Next.js app + Shield APK v1.4 + source) - compose/hf-pdocker-02/hobbs-organizer: override (local-disk secrets, watchtower off), .env (port 8340), Shield provisioning script - CLAUDE.md: service tree + internal ports Trusted-LAN mode. Secrets live only on .100 /var/lib/hobbs-organizer/secrets (not in git). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E9NnVEico3WvFxLyjy1iW3
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { createHash, timingSafeEqual } from "node:crypto";
|
|
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
|
|
function tokenMatches(actual: string, expected: string) {
|
|
const actualValue = createHash("sha256").update(actual).digest();
|
|
const expectedValue = createHash("sha256").update(expected).digest();
|
|
return timingSafeEqual(actualValue, expectedValue);
|
|
}
|
|
|
|
export function proxy(request: NextRequest) {
|
|
if (request.nextUrl.pathname === "/api/health") return NextResponse.next();
|
|
|
|
const configuredToken = process.env.ORGANIZER_ACCESS_TOKEN?.trim();
|
|
if (!configuredToken) return NextResponse.next();
|
|
|
|
const authorization = request.headers.get("authorization") || "";
|
|
const suppliedToken = authorization.startsWith("Bearer ") ? authorization.slice(7) : "";
|
|
if (tokenMatches(suppliedToken, configuredToken)) return NextResponse.next();
|
|
|
|
return NextResponse.json(
|
|
{ error: "Unauthorized" },
|
|
{
|
|
status: 401,
|
|
headers: {
|
|
"Cache-Control": "no-store",
|
|
"WWW-Authenticate": "Bearer realm=\"Hobbs Family Organizer\"",
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/((?!api/health).*)"],
|
|
};
|