Fixed the Manager deployment database dependency.
CI / ci (push) Canceled after 0s

Root cause
src/proxy.ts statically imported installation-state.ts, which statically imported Prisma. Additionally, the root layout statically imported business branding, which also loads Prisma. The pathname check was also incorrect for Manager deployments served at /.
This commit is contained in:
Stefan Lazic committed 2026-09-04 21:43:26 +01:00
1 parent 7f774e95bb
commit a8cdc2671e
3 files changed
+92 -10

No files matched your search

+15 -9
View File
@@ -1,7 +1,6 @@
import NextAuth from "next-auth";
import { NextResponse } from "next/server";
import { NextResponse, type NextRequest } from "next/server";
import { authConfig } from "@/auth.config";
import { isInstalledForRequest } from "@/lib/installation/installation-state";
// /home, /appointments and /settings are intentionally NOT hard-gated here
// as of Phase 4 — Home must work for guests (public business browsing +
@@ -21,7 +20,6 @@ const PROTECTED_PREFIXES = ["/staff", "/owner"];
// business data guard themselves (see /api/health and
// /api/cron/process-notifications).
const INSTALL_EXEMPT_PREFIXES = [
"/manager",
"/install",
"/offline",
"/manifest.webmanifest",
@@ -84,17 +82,23 @@ function buildCsp(): string {
].join("; ");
}
export default auth(async (req) => {
export async function handleProxyRequest(req: NextRequest) {
const { pathname } = req.nextUrl;
const csp = buildCsp();
// Manager is a separate deployment and hostname, so its root pathname is
// normally `/`, not `/manager`. Branch before loading any business module.
if (process.env.MANAGER_MODE === "true") {
const response = NextResponse.next();
response.headers.set("Content-Security-Policy", csp);
return response;
}
const isInstallExempt = INSTALL_EXEMPT_PREFIXES.some(
(prefix) => pathname === prefix || pathname.startsWith(prefix.endsWith("/") ? prefix : `${prefix}/`),
);
// The platform Manager is a separate deployment and deliberately has no
// business database. Its own session guard runs inside /manager pages/API.
const isManagerPath = pathname === "/manager" || pathname.startsWith("/manager/");
const installed = isManagerPath ? true : await isInstalledForRequest();
const { isInstalledForRequest } = await import("@/lib/installation/installation-state");
const installed = await isInstalledForRequest();
if (!installed && !isInstallExempt) {
const response = NextResponse.redirect(new URL("/install", req.nextUrl.origin));
@@ -126,7 +130,9 @@ export default auth(async (req) => {
const response = NextResponse.next();
response.headers.set("Content-Security-Policy", csp);
return response;
});
}
export default auth(handleProxyRequest);
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],