CI / ci (push) Canceled after 0s
1. Root cause of the database error The Manager proxy was bypassing installation checks, but / still resolved to src/app/page.tsx, which statically imported: - @/auth - Prisma - business branding - business permissions - primary business data The root route now redirects to /manager inside the proxy before the business homepage is evaluated. 2. Root cause of the Auth.js error The global business SessionProvider was mounted around Manager pages. It automatically requested: The business homepage is not evaluated first. 5. Provider and authentication separation Manager mode: - Uses ManagerProviders - Uses the signed Manager cookie session - Does not mount SessionProvider - Does not call /api/auth/session - Does not import business Auth.js or Prisma Business mode: - Dynamically loads the existing business Providers - Continues using Auth.js and SessionProvider - Preserves installation, /owner, and /staff behavior 6. Database independence Manager mode now avoids database initialization for: - Proxy requests - Root metadata and viewport - Root routing - Manager pages - Manager APIs - Manifest requests - Health requests - Business Auth.js requests - Business cron requests No fake DATABASE_* variables were added. 7. Tests Added coverage for: - Manager / routing - Manager /manager access - No installation-state check in Manager mode - Prisma import protection - Business installation checks - /owner protection - Business Auth.js 404 boundary - Manager health route without Prisma - Manager manifest without business branding 8. Validation
43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { secretsMatch } from "@/lib/security/secrets-match";
|
|
|
|
/**
|
|
* External trigger for the Google Reviews sync — mirrors
|
|
* /api/cron/process-notifications exactly (same CRON_SECRET bearer-token
|
|
* auth, same 503-if-unconfigured / 401-if-wrong / skip-if-not-installed
|
|
* shape). Recommended frequency: every 24 hours — reviews don't change
|
|
* fast enough to justify Google Places API calls any more often than
|
|
* that, and the customer app never calls Google directly regardless (see
|
|
* src/services/reviews/reviews.service.ts).
|
|
*
|
|
* Safe to run concurrently with itself: syncGoogleReviewsForBusiness only
|
|
* overwrites Business.googleRating/googleRatingCount with whatever Google
|
|
* returns, so an overlapping call just re-writes the same two columns,
|
|
* never duplicates anything.
|
|
*/
|
|
export async function POST(request: Request) {
|
|
if (process.env.MANAGER_MODE === "true") return NextResponse.json({ error: "Not available on Manager." }, { status: 404 });
|
|
|
|
const secret = process.env.CRON_SECRET;
|
|
if (!secret) {
|
|
return NextResponse.json({ error: "CRON_SECRET is not configured on this deployment." }, { status: 503 });
|
|
}
|
|
|
|
const provided = request.headers.get("authorization");
|
|
if (!provided || !secretsMatch(provided, `Bearer ${secret}`)) {
|
|
return NextResponse.json({ error: "Unauthorized." }, { status: 401 });
|
|
}
|
|
|
|
const { isInstalledForRequest } = await import("@/lib/installation/installation-state");
|
|
if (!(await isInstalledForRequest())) {
|
|
return NextResponse.json({ skipped: "not_installed" });
|
|
}
|
|
|
|
const [{ prisma }, { syncGoogleReviewsForAllBusinesses }] = await Promise.all([
|
|
import("@/lib/db/prisma"),
|
|
import("@/services/reviews/review-sync.service"),
|
|
]);
|
|
const results = await syncGoogleReviewsForAllBusinesses(prisma);
|
|
return NextResponse.json({ results });
|
|
}
|