point-source / supabase-tenant-rbac

A template for implementing basic RBAC for a multi-tenant supabase project
BSD 2-Clause "Simplified" License
306 stars 25 forks source link

Add invite feature #7

Closed bangdragon closed 4 months ago

bangdragon commented 1 year ago

As you said:

I've also recently created an invite system built on this and supabase edge functions which allows group owners to generate a token which other users can use to join their group with a specific pre-selected role. I have not yet extensively tested it but if you are interested in this code as well

Please add this feature. Thanks

bangdragon commented 1 year ago

I have one question. In this following code:

set check_function_bodies = off;

CREATE OR REPLACE FUNCTION public.set_group_owner()
 RETURNS trigger
 LANGUAGE plpgsql
 SECURITY DEFINER
AS $function$
    begin
        IF auth.uid() IS not NULL THEN 
        insert into public.group_users(group_id, user_id, role) values(new.id, auth.uid(), 'owner');
        end if;
        return new;
    end;
$function$
;

CREATE TRIGGER on_insert_set_group_owner AFTER INSERT ON public.groups FOR EACH ROW EXECUTE FUNCTION set_group_owner();

Why need to set check_function_bodies = off;

point-source commented 1 year ago

Why need to set check_function_bodies = off;

Actually, we don't. Feel free to remove or skip that. It gets automatically added by the diff tool when I use supabase's cli to create the migration scripts.

point-source commented 11 months ago

Just popping in to say I haven't forgotten this. Just been busy. This is on my to-do list.

nikitastryuk commented 9 months ago

this would be great addition

point-source commented 8 months ago

I have added this in the dev branch. An updated TLE is coming soon but is currently blocked by this bug.

crllnsmnn commented 8 months ago

@point-source First of all - thank you, great work! I am looking forward to this extension! Is it possible to extend the invitation logic to allow multiple roles when creating the invitation? This would allow more complicated role setups right after invitation.