fix(orders): use client PB for customer list in modal mount

getAdminPocketBase reads PB_ADMIN_EMAIL/PB_ADMIN_PASSWORD which are
server-only env vars. The modal mount is a client component, so the
admin client would fail to authenticate at runtime. The users PB
session already has read access; switch to getPocketBase.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
SJCoetz 2026-07-29 16:19:40 +02:00
parent 8b6b10d64b
commit 064f13a7ca

View file

@ -104,12 +104,16 @@ function OrdersReviewModalMount({
(async () => {
try {
const { getOrder, getOrderItems } = await import("@/lib/pb-helpers");
const { getAdminPocketBase } = await import("@/lib/server/pocketbase-admin");
const adminPb = await getAdminPocketBase();
// Use the BROWSER PB instance (not the admin one) — admin PB
// requires server-only env vars and would break in the browser
// bundle. The user's session PB already has read access to
// customers + quote_attachments, so we don't need privileges.
const { getPocketBase } = await import("@/lib/pocketbase");
const pb = getPocketBase();
const [order, items, customersResult] = await Promise.all([
getOrder(orderId),
getOrderItems(orderId),
adminPb.collection("customers").getFullList({
pb.collection("customers").getFullList({
sort: "-created",
expand: "company",
}),
@ -125,7 +129,7 @@ function OrdersReviewModalMount({
| undefined;
const attachments = quote
? await adminPb
? await pb
.collection("quote_attachments")
.getFullList({
filter: `quote = "${quote.id}"`,