basejump icon indicating copy to clipboard operation
basejump copied to clipboard

how to delete a team account?

Open haramishra opened this issue 1 year ago • 3 comments

I couldn't find the API to delete a team account on base jump docs. Please help me out.

haramishra avatar May 08 '24 17:05 haramishra

1. Add new policy on basejump.accounts

"Account can be deleted by primary owner" with check " (primary_owner_user_id = auth.uid())"

2. Expose basejump scheme from API

Go to settings -> Api -> Exposed schema and add basejump here

!! Warning, make sure your policies are correct. I did only a brief check and it seems basejump has sane defaults, but the risk is on you.

3. Query from client using basejump and not public schema

      const { data, error } = await supabase
        .schema("basejump")
        .from("accounts")
        .delete()
        .eq("id", workspaceId);

qnsi avatar May 21 '24 08:05 qnsi

We do not wish to expose the entire basejump schema public as mentioned above.

Is there a function / rest api to delete the team?

airsherlock avatar Jul 02 '24 03:07 airsherlock

@airsherlock I think you'd have to write the function yourself.

Something like this:


**
  Allows an owner to delete an existing account
 */

create or replace function public.delete_account(account_id uuid)
    returns void
    language plpgsql
as
$$
begin
    -- verify account owner for the account
    if basejump.has_role_on_account(
               delete_account.account_id, 'owner') <>
       true then
        raise exception 'Only account owners can delete accounts';
    end if;

    delete from basejump.accounts where id = delete_account.account_id;
end
$$;

grant execute on function public.delete_account(uuid) to authenticated;

cloudorbush avatar Aug 15 '24 09:08 cloudorbush