Thomas B
10/30/2021, 7:32 PMSECURITY DEFINER SET search_path = public, extensions
), which I HAVE to have otherwise the Auth stuff wont work, and the extension does not either. (Inviting an user via the dashboard just gives an error without it). More or less just wanted to ask if adding extensions to the DEFINER is an okay practice.HarryET
10/30/2021, 8:00 PMHarryET
10/30/2021, 8:00 PMThomas B
10/30/2021, 8:03 PMCREATE TRIGGER on_user_signup
AFTER INSERT
ON auth.users
FOR EACH ROW
EXECUTE PROCEDURE handle_new_user();
I just felt like no "security" would be needed if it is the server that uses the function, which it is. Guess I still am a bit confused what this SECURITY DEFINER stuff is exactly.HarryET
10/30/2021, 8:05 PMSECURITY DEFINER
or SECURITY INVOKER
it means should the functions code be run as the person who made it or as the person running it.HarryET
10/30/2021, 8:05 PMThomas B
10/30/2021, 8:08 PMHarryET
10/30/2021, 8:19 PMHarryET
10/30/2021, 8:19 PMdafri
10/31/2021, 1:09 PMschema_migrations
table from the remote supabase database. When running supabase start
I get now an error for a custom enum type that I created, e.g. Error: Error running SQL: ERROR: type "widget_type" does not exist
. The type creation is part of the [...]_link.sql
migration but appears at the end of the file. When I manually move it at the top, the previous error disappears but I now get a relation error for some tables, e.g. Error: Error running SQL: ERROR: relation "public.group" does not exist
. I guess I'm doing something completely wrong here š
Would appreciate any hints!tourdownunder
10/31/2021, 11:53 PMIlko Kacharov
11/01/2021, 5:00 AMtourdownunder
11/01/2021, 7:47 AMIlko Kacharov
11/01/2021, 7:51 AMlnraahCC
11/01/2021, 8:14 AMisosceleskramer
11/01/2021, 8:36 AMchipilov
11/01/2021, 9:15 AMdafri
11/02/2021, 11:57 AMERROR: must be owner of table XX (SQLSTTE 42501)
when trying to run supabase deploy
(the migration only adds a field to table XX).
If I set the postgres
user on app.supabase.io to be a SUPERUSER it works (ALTER USER postgres WITH SUPERUSER;
) but this doesn't feel right. Does someone know what would be the recommended way here to apply the migrations on the remote database?jonny
11/02/2021, 12:58 PMconfig_wizard
11/02/2021, 4:17 PMcreate table public.keys (
id uuid references auth.users not null,
inserted_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
address text,
data text,
primary key (id)
);
alter table public.keys enable row level security;
create policy "Users can insert their own keys."
on public.keys for insert
with check ( auth.uid() = id );
create policy "Users can view their own keys."
on public.keys for select
using ( auth.uid() = id );
CREATE POLICY "Users can delete own keys."
ON public.keys
FOR DELETE USING (
auth.uid() = user_id
);
javascript from webbrowser
//from webbrowser
const { response, error } = await supabase
.from('keys')
.insert([
{ address: address, data}
],
{ returning: 'minimal' })
returns me 'new row violates row-level security policy for table "keys"'
config_wizard
11/02/2021, 4:19 PMcreate policy "Users can insert their own keys."
on public.keys for insert
with check ( auth.role() = 'authenticated'::text );
but in that case I would have to set the auth user ID manually so seems that the above is better?garyaustin
11/02/2021, 4:24 PMconfig_wizard
11/02/2021, 4:26 PMconfig_wizard
11/02/2021, 4:29 PMPragy
11/04/2021, 2:36 PMprofiles
.
RLS is enabled.
sql
create table if not exists profiles
(
user_id uuid primary key references auth.users,
uid uuid not null unique default uuid_generate_v4(),
username citext not null unique check (char_length(username) >= 3),
full_name text not null,
avatar_url text,
is_public boolean default true
);
alter table profiles enable row level security;
comment on table profiles is 'User Profiles';
create index if not exists on profiles(is_public);
create index if not exists on profiles(created_at);
create index if not exists on profiles(updated_at);
The only policy provided is on select
sql
create policy anyone_can_view_public_profiles_and_users_can_view_own_profile on profiles for select using (is_public or auth.uid() = user_id);
I'm creating functions for create and update
sql
create or replace function create_profile()
returns profiles as $$
BEGIN
insert into profiles (user_id, username, full_name)
values (auth.uid(), auth.uid(), auth.name())
returning *;
end;
$$ language plpgsql;
create or replace function update_profile(username citext, full_name text, avatar_url text, is_public boolean)
returns profiles as $$
BEGIN
update profiles
set username=username,
full_name=full_name,
avatar_url=avatar_url,
is_public=is_public
where user_id = auth.uid()
returning *;
end;
$$ language plpgsql;
My question is:
1. when I execute these functions directly via the database (using a client like dbeaver), then what value does auth.uid()
have?
2. How do I get the user's name via sql? auth.name()
doesn't seem to work
3. Is it okay to do what I'm doing here? Or am I doing this wrong? š
Scott P
11/04/2021, 3:09 PMPragy
11/04/2021, 3:31 PMid
and internal user_id
to the users. They should only be able to see the corresponding uuids generated for public view.
PostgREST suggests that creating views is the correct way of doing this. However, I'm not sure how the RLS will work with views.
Postgresql docs here seem to say that views aren't affected by RLS š¦
https://www.postgresql.org/docs/10/sql-createpolicy.htmlchipilov
11/04/2021, 3:34 PMPragy
11/04/2021, 4:41 PMset role authenticated;
but that wasn't allowed.chipilov
11/04/2021, 6:27 PM