-- Drop and recreate the "Anyone can create orders" policy to ensure it works correctly
drop policy if exists "Anyone can create orders" on public.orders;

-- Allow authenticated users to create orders
create policy "Authenticated users can create orders"
  on public.orders for insert
  to authenticated
  with check (true);

-- Also allow anon users to create orders (for guest checkout if needed)
create policy "Anonymous users can create orders"
  on public.orders for insert
  to anon
  with check (true);

-- Add INSERT policy for chits so orders can create chits
create policy "Authenticated users can create chits"
  on public.chits for insert
  to authenticated
  with check (true);

-- Also allow anon users to create chits (for guest checkout if needed)
create policy "Anonymous users can create chits"
  on public.chits for insert
  to anon
  with check (true);
