Trage deine kostenlosen Supabase-Zugangsdaten ein, um die App mit allen Haushaltsmitgliedern zu teilen.
So erhältst du die Zugangsdaten:
1. Gehe zu
supabase.com → Kostenlos registrieren
2. Neues Projekt erstellen
3. Settings → API → URL + anon key kopieren
4. SQL Editor → unten stehende Tabellen anlegen
-- 1. Tabellen erstellen
create table if not exists households (id uuid primary key default gen_random_uuid(), name text, invite_code text unique default substr(md5(random()::text),1,8), created_at timestamptz default now());
create table if not exists profiles (id uuid primary key references auth.users, name text, household_id uuid references households, avatar text);
create table if not exists meal_plan (id uuid primary key default gen_random_uuid(), household_id uuid references households, date text, slot int, recipe_id int, recipe_name text, recipe_emoji text, recipe_cal text, added_by text, created_at timestamptz default now());
create table if not exists shopping_items (id uuid primary key default gen_random_uuid(), household_id uuid references households, name text, qty text, category text, checked boolean default false, added_by text, created_at timestamptz default now());
create table if not exists fridge_items (id uuid primary key default gen_random_uuid(), household_id uuid references households, name text, emoji text, days_left int, expiry text, added_by text, created_at timestamptz default now());
create table if not exists saved_recipes (id uuid primary key default gen_random_uuid(), household_id uuid references households, recipe_id int, recipe_data jsonb, added_by text, created_at timestamptz default now());
-- 2. RLS aktivieren
alter table households enable row level security;
alter table profiles enable row level security;
alter table meal_plan enable row level security;
alter table shopping_items enable row level security;
alter table fridge_items enable row level security;
alter table saved_recipes enable row level security;
-- 3. Alte Policies löschen (falls vorhanden)
drop policy if exists "household_access" on meal_plan;
drop policy if exists "household_access" on shopping_items;
drop policy if exists "household_access" on fridge_items;
drop policy if exists "household_access" on saved_recipes;
drop policy if exists "own_profile" on profiles;
drop policy if exists "profile_insert" on profiles;
drop policy if exists "profile_update" on profiles;
drop policy if exists "household_read" on households;
drop policy if exists "household_insert" on households;
drop policy if exists "household_update" on households;
-- 4. Neue vollständige Policies
-- households: jeder eingeloggte User darf erstellen; eigenen Haushalt lesen/ändern
create policy "household_insert" on households for insert to authenticated with check (true);
create policy "household_read" on households for select using (id in (select household_id from profiles where id = auth.uid()));
create policy "household_update" on households for update using (id in (select household_id from profiles where id = auth.uid()));
-- profiles: eigenes Profil verwalten
create policy "profile_insert" on profiles for insert with check (id = auth.uid());
create policy "profile_select" on profiles for select using (true);
create policy "profile_update" on profiles for update using (id = auth.uid());
-- meal_plan: Haushaltsmitglieder dürfen alles
create policy "meal_select" on meal_plan for select using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "meal_insert" on meal_plan for insert with check (household_id in (select household_id from profiles where id = auth.uid()));
create policy "meal_update" on meal_plan for update using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "meal_delete" on meal_plan for delete using (household_id in (select household_id from profiles where id = auth.uid()));
-- shopping_items
create policy "shop_select" on shopping_items for select using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "shop_insert" on shopping_items for insert with check (household_id in (select household_id from profiles where id = auth.uid()));
create policy "shop_update" on shopping_items for update using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "shop_delete" on shopping_items for delete using (household_id in (select household_id from profiles where id = auth.uid()));
-- fridge_items
create policy "fridge_select" on fridge_items for select using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "fridge_insert" on fridge_items for insert with check (household_id in (select household_id from profiles where id = auth.uid()));
create policy "fridge_delete" on fridge_items for delete using (household_id in (select household_id from profiles where id = auth.uid()));
-- saved_recipes
create policy "saved_select" on saved_recipes for select using (household_id in (select household_id from profiles where id = auth.uid()));
create policy "saved_insert" on saved_recipes for insert with check (household_id in (select household_id from profiles where id = auth.uid()));
create policy "saved_delete" on saved_recipes for delete using (household_id in (select household_id from profiles where id = auth.uid()));