DocHub
Restaurant owner access, assignment lookups, order management

Manager Console Fixes

Problem

Restaurant owners and clerks could not access the manager console. Multiple API routes had UUID vs numeric ID mismatches in authorization checks.

Fixes by Route

/api/admin/restaurants/route.ts

  • restaurants table has no legacy_numeric_id column — replaced with id
  • owner_user_id is UUID but was queried with numeric legacy_numeric_id — switched to auth.uid
  • Added assignments table lookup so assigned restaurants (not just owned) are found

/api/admin/orders/route.ts

  • userHasAssignmentForRestaurant was querying UUID column with numeric ID — fixed to use auth.uid
  • Owner check was comparing UUID with number — fixed to compare UUIDs

/api/admin/orders/[orderId]/route.ts

  • Same UUID fix for assignment lookup in both GET and PATCH handlers

/api/order-detail/[orderId]/route.ts

  • Response was missing firestore_id on order object — added firestore_id: String(order.id)
  • Same UUID fix for assignment lookup

SWR Performance Fix

Page transitions were very slow due to aggressive SWR config in src/lib/swrConfig.ts:

Setting Before After
revalidateOnFocus true false
dedupingInterval 2000ms (2s) 30000ms (30s)
keepPreviousData not set true

This means navigating back to a previously visited page shows cached data instantly instead of a loading spinner, and switching browser tabs no longer triggers refetches.