From 66c6f45efcd067c5f5bc7d0c9fc24305b8802f14 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 Jun 2026 17:37:17 +0000 Subject: [PATCH] fix(admin/stops): pass admin user_id, not stop.id, as callerUid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StopDetailModal was hardcoding callerUid={stop.id} when rendering StopProductAssignment, so assign_product_to_stop received the stop's own UUID as p_caller_uid. The RPC's admin_users.user_id lookup returned no row, so every assign attempt failed with 'Not recognized as admin'. The admin's user_id is already known inside the getStopDetails server action (it gates on getAdminUser()), so surface it on the response and read it in the modal. The sibling /admin/stops/[id] page already uses the same source (adminUser.user_id) — this brings the modal in line with it. --- src/actions/stops/get-stop-details.ts | 3 +++ src/components/admin/StopDetailModal.tsx | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/actions/stops/get-stop-details.ts b/src/actions/stops/get-stop-details.ts index c31bc78..69f3494 100644 --- a/src/actions/stops/get-stop-details.ts +++ b/src/actions/stops/get-stop-details.ts @@ -32,6 +32,8 @@ export type StopDetailsResult = allProducts: { id: string; name: string; type: string; price: number }[]; assignedProducts: AssignedProduct[]; brands: { id: string; name: string; slug: string }[]; + /** admin_users.user_id of the caller, forwarded to RPCs that authorise via user_id lookup */ + callerUid: string; } | { success: false; error: string }; @@ -115,5 +117,6 @@ export async function getStopDetails(stopId: string): Promise allProducts: allProducts ?? [], assignedProducts: (productStops ?? []) as AssignedProduct[], brands: brands ?? [], + callerUid: adminUser.user_id, }; } diff --git a/src/components/admin/StopDetailModal.tsx b/src/components/admin/StopDetailModal.tsx index 2cd16e8..a44a8fa 100644 --- a/src/components/admin/StopDetailModal.tsx +++ b/src/components/admin/StopDetailModal.tsx @@ -31,6 +31,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props) const [allProducts, setAllProducts] = useState<{ id: string; name: string; type: string; price: number }[]>([]); const [assignedProducts, setAssignedProducts] = useState([]); const [brands, setBrands] = useState<{ id: string; name: string; slug: string }[]>([]); + const [callerUid, setCallerUid] = useState(""); const [tab, setTab] = useState("details"); useEffect(() => { @@ -49,6 +50,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props) setAllProducts(res.allProducts); setAssignedProducts(res.assignedProducts); setBrands(res.brands); + setCallerUid(res.callerUid); setLoading(false); }) .catch((err) => { @@ -68,6 +70,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props) setAllProducts(res.allProducts); setAssignedProducts(res.assignedProducts); setBrands(res.brands); + setCallerUid(res.callerUid); }); } @@ -145,7 +148,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props) stopId={stop.id} allProducts={allProducts} assignedProducts={assignedProducts} - callerUid={stop.id} + callerUid={callerUid} />