Three callers, one schema
Three principals reach the database. The anon key powers the public storefront and can only read storefront-eligible rows. The authenticated key (a signed-in customer) unlocks order history scoped to the caller. The service role key is used once, inside the checkout server action, to create an orders row even when the buyer is anonymous. Admin access is layered on top of the authenticated key via an admin_users membership check.
- anon
- read storefront_status='live' rows on products / variants / images / tags
- authenticated
- read own orders; read full product catalog
- admin (via is_admin)
- all writes on products / variants / inventory / promotions / orders
- service_role
- reserved for checkout order creation; never exposed to the client