From 35e340eed2408a4487dcea98a4af12f69f1bb4b7 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Tue, 18 Mar 2025 10:07:06 -0500 Subject: [PATCH] Allow users to update other statuses. Add column in statutes for that --- components/auth/Auth.tsx | 1 - scripts/supabase_schema.sql | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/auth/Auth.tsx b/components/auth/Auth.tsx index 824719a..3c6fc09 100644 --- a/components/auth/Auth.tsx +++ b/components/auth/Auth.tsx @@ -6,7 +6,6 @@ import AppleSignInButton from '@/components/auth/AppleSignIniOS'; import AzureSignIn from './AzureSignIn'; import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; -import type { updateUser } from '@/constants/Types'; // Tells Supabase Auth to continuously refresh the session automatically if // the app is in the foreground. When this is added, you will continue to receive diff --git a/scripts/supabase_schema.sql b/scripts/supabase_schema.sql index 253d361..3778cb4 100644 --- a/scripts/supabase_schema.sql +++ b/scripts/supabase_schema.sql @@ -63,6 +63,7 @@ create policy "Anyone can upload an avatar." on storage.objects CREATE TABLE statuses ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, user_id uuid REFERENCES auth.users ON DELETE CASCADE NOT NULL, + updated_by_id uuid REFERENCES auth.users ON DELETE SET NULL DEFAULT auth.uid(), created_at timestamp with time zone DEFAULT now() NOT NULL, status text NOT NULL, CONSTRAINT status_length CHECK (char_length(status) >= 3 AND char_length(status) <= 80), @@ -77,8 +78,8 @@ ALTER TABLE statuses CREATE POLICY "Public statuses are viewable by everyone." ON statuses FOR SELECT USING (true); -CREATE POLICY "Users can insert their own statuses." ON statuses - FOR INSERT WITH CHECK ((SELECT auth.uid()) = user_id); +CREATE POLICY "Users can insert statuses for any user." ON statuses + FOR INSERT WITH CHECK (auth.role() = 'authenticated'); -- Function to add first status CREATE FUNCTION public.handle_first_status() @@ -86,8 +87,9 @@ RETURNS TRIGGER SET search_path = '' AS $$ BEGIN - INSERT INTO public.statuses (user_id, status) + INSERT INTO public.statuses (user_id, updated_by_id, status) VALUES ( + NEW.id, NEW.id, 'Just joined!' );