nahtnam
09/02/2022, 8:35 PMON DELETE CASCADE
in the UI or does it need to be done through SQL?Wickey
09/02/2022, 9:21 PMiLikeBikes
09/02/2022, 10:43 PMauth.user
table I have added a uuid field that corresponds with another table's uuid field in attempt to create group permissions.
I have been following this template, but I have not been able to get it to work. are there others trying to setup grouping rls policies. is this something that supabase is working on?
https://github.com/supabase/supabase/discussions/1148
-- step 1: add agency_id to raw_user_meta_data
UPDATE auth.users
SET raw_user_meta_data = auth.users.raw_user_meta_data::jsonb - 'agency_id' || '{"agency_id":"df56814f-46ab-4d1c-9e4e-6393e727b212"}'
where auth.users.email = 'walter.k.jenkins@gmail.com'
-- step 2: create function
create or replace function auth.orgid() returns uuid as $$
select nullif(
((current_setting('request.jwt.claims')::jsonb ->> 'raw_user_meta_data')::jsonb ->> 'agency_id'),
'')::uuid
$$ language sql;
-- step 3: set policy
create policy "allow read/write access to boards for users of the same organization"
on public.notes for all using (
(auth.orgid() = notes.agency_id)
);
n10000k
09/02/2022, 11:12 PMsql
-- create teams table
create table teams (
id bigint generated by default as identity primary key,
creator uuid references users not null default auth.uid(),
title text default 'Untitled',
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- teams row level security
alter table teams enable row level security;
-- policies
create policy "Users can create teams" on teams for
insert to authenticated with check (true);
ts
const createTeam = (title: string) =>
supabase
.from('teams')
.insert({ title });
Is returning
code: "42501"
details: null
hint: null
message: "new row violates row-level security policy for table \"teams\""
owonwo
09/02/2022, 11:38 PMPeanut
09/03/2022, 5:11 AMCREATE TABLE assets (
id TEXT PRIMARY KEY,
title TEXT
)
I have table "assetmeta":
CREATE TABLE assetmeta (
id TEXT PRIMARY KEY,
accessstatus TEXT
)
I have a view "getpublicassets":
CREATE VIEW getpublicassets AS
SELECT * FROM assets LEFT JOIN assetsmeta ON assetsmeta.id = assets.id
WHERE accessstatus = 'public'
Then I run it:
SELECT * FROM getpublicassets LIMIT 100
When I EXPLAIN ANALYZE it says it is performing a loop for each row and it's slow. What can I do to optimize my view?
Tried adding an index:
CREATE INDEX asset_public ON assetmeta (
accessstatus ASC
);
Doesnt seem to matterHaus Of Alejandro
09/03/2022, 7:32 AMgbb
09/03/2022, 8:33 AMcreate or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public.profiles (id, email, lastName, firstName)
values (new.id, new.email, new.raw_user_meta_data->>'lastName', new.raw_user_meta_data->>'firstName');
return new;
end;
$$;
-- trigger the function every time a user is created
drop trigger if exists on_auth_user_created on auth.user;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
During the signup I send the following data:
const { user, error } = await supabase.auth.signUp(
{
email,
password,
},
{
data: {
lastName,
firstName,
},
}
);
I made sure to validate the first and last name before I do this. yet, I get an error when creating the db, but I don't know why..
error in createUser { message: 'Database error saving new user', status: 500 }
Id really need some help heretonyhart
09/03/2022, 11:11 AMNin
09/03/2022, 12:12 PMCREATE OR REPLACE FUNCTION public.tid(
)
RETURNS uuid
LANGUAGE 'sql'
COST 100
STABLE PARALLEL UNSAFE
AS $BODY$
select
coalesce(
(nullif(current_setting('request.jwt.claims', true), '')::jsonb #>> '{user_metadata, tenant_id}')
)::uuid
$BODY$;
ALTER FUNCTION public.tid()
OWNER TO supabase_auth_admin;
GRANT EXECUTE ON FUNCTION public.tid() TO PUBLIC;
GRANT EXECUTE ON FUNCTION public.tid() TO anon;
GRANT EXECUTE ON FUNCTION public.tid() TO authenticated;
GRANT EXECUTE ON FUNCTION public.tid() TO dashboard_user;
GRANT EXECUTE ON FUNCTION public.tid() TO service_role;
GRANT EXECUTE ON FUNCTION public.tid() TO supabase_auth_admin;
COMMENT ON FUNCTION public.tid()
IS 'Returns the currently logged in users tenant id';
Mat
09/03/2022, 1:29 PMunexpected response from login query
any ideas?mathewcst
09/03/2022, 2:47 PMKTibow
09/03/2022, 5:08 PMchat
and users
. chat
has some columns like where the message was sent in, the message contents, and the email of the person who sent the message. users
has a user's email, name, and profile picture URL. Right now I have some code like this:
js
export const connectToMessages = async (channelGetter) => {
return supabase
.from("chat")
.on("INSERT", async (payload) => {
const newMessage = payload.new;
console.debug("recieved message", newMessage);
if (newMessage != channelGetter()) return;
const { data } = await supabase
.from("chat")
.select("contents, users ( name, profile_picture )")
.eq("id", payload.new.id);
messages.set([...get(messages), data[0]]);
})
.subscribe();
}
But this means it's laggy because it has to make a whole new query for each message. Is there a way to fetch the user and send it in realtime, or does anyone have any other recommendations?TrueTrader
09/03/2022, 6:10 PMcapezolo
09/03/2022, 8:40 PMFunHellion
09/03/2022, 9:07 PMtypescript
supabase
.channel("public:events")
.on("postgres_changes", { event: "*", schema: "public", table: "events" }, (payload: any) => {
console.log("Change in events", payload);
})
.subscribe();
When I make a change nothing seems to be popping up in the console.
Environment:
- React v18.2.0
- Supabase-js v2.0.0-rc.6Honeyandtoast
09/03/2022, 10:00 PMtEjAs
09/03/2022, 10:45 PMhttp418
09/03/2022, 11:30 PMKasper
09/04/2022, 12:02 AMsb-access-token
cookie value to createClient
in supabase-js
v2, but it's not returning a session. Any ideas why this isn't working?
ts
const supabaseClient = createClient<Database>(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
global: {
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
},
})
const session = await supabaseClient.auth.getSession() // returns null
lanbau
09/04/2022, 1:36 AMKTibow
09/04/2022, 1:52 AMHoneyandtoast
09/04/2022, 2:49 AMnahtnam
09/04/2022, 4:31 AMAutarch
09/04/2022, 6:55 AMarch
09/04/2022, 7:14 AMsamuele
09/04/2022, 7:58 AMjxyz
09/04/2022, 8:12 AMash
09/04/2022, 8:33 AMHaus Of Alejandro
09/04/2022, 8:52 AM