midday-ai / midday

Run your business smarter 🪄
https://midday.ai
GNU Affero General Public License v3.0
4.99k stars 432 forks source link

postgress migration error on vanilla setup #248

Closed absolutegravitas closed 1 week ago

absolutegravitas commented 2 weeks ago

PostgrestError: permission denied for view current_user_teams when intially signing up / logging in on a local version of the repo with local supabase. Possibly related to https://github.com/midday-ai/midday/issues/185 as when i force go to /setup obviously I bypass the inbox / teams etc. routes and go through intial setup as expected.

Steps: 1 - start local supabase db via supabase cli using supabase start image image

2 - update / add env vars

3 - update config.toml to include oAuth credentials / redirects image

4 - run supabase db reset to run migrations and seed script -- these appear to run without errors image

5 - run bun dev to test just dashboard part of the apps suite in /src/apps/dashboard. image

6 - Go to localhost:3001/login to do oAuth flow image

7- Auth flow works, user is redirected to localhost per config.toml as expected however page doesnt render due to the below error. This looks like one or more of the following migration sqls do not run even though the console screenshots above indicate otherwise. Specifically permissions on the current_user_teams view for the just authenticated user. image image

absolutegravitas commented 1 week ago

@pontusab

Managed to make my local build of the dashboard to work with most of the functionality intact. Various mods to the migrations which are incorrect / cause issues. Especially:

-- Create or replace function to get current user's team ID CREATE OR REPLACE FUNCTION public.get_current_user_team_id() RETURNS uuid LANGUAGE plpgsql AS $$ BEGIN RETURN (SELECT team_id FROM users WHERE id = auth.uid()); END; $$;

-- Drop existing policy DROP POLICY IF EXISTS "Enable read access for all users" ON public.users_on_team;

-- Create new policy CREATE POLICY "Team Member Access" ON public.users_on_team AS PERMISSIVE FOR SELECT TO authenticated USING ( EXISTS ( SELECT 1 FROM private.current_user_teams cut WHERE cut.user_id = auth.uid() AND cut.team_id = users_on_team.team_id ) );

-- Re-enable function body checking SET check_function_bodies = ON;


- i gave up on trigger.dev complaining about private API key being used and just commented affected <TriggerProvider and other code out for the dashboard to actually show a UI. Can't find any references online or in their docs and also tried removing `NEXT_PUBLIC_` prefix in case that was the issue to no effect.
![image](https://github.com/user-attachments/assets/d864f7a4-de4c-4149-9e82-2c63771c8643)