lewisd
09/18/2022, 1:18 PMGabriel Feitosa
09/18/2022, 5:01 PMsaeros
09/18/2022, 5:40 PMak4zh
09/18/2022, 5:44 PMSonny Vesali
09/18/2022, 6:19 PMCREATE OR REPLACE FUNCTION add_token_table(token_name text)
returns void as $$
BEGIN
execute format(
'create table', token_name, '(hexBalance text)'
);
END
$$ language plpgsql
What am I missing here, also I haven't found anything that is terribly too helpful for writing these kinds of postgres functions so if anyone has any resources that help them write these sorts of functions easily, also feel free to drop those as well, ThanksAnimeDev
09/18/2022, 6:30 PMRexrider
09/18/2022, 6:44 PMthestepafter
09/18/2022, 7:11 PMlewisd
09/18/2022, 8:05 PMcreate function create_listing_liked_notification (receiver_id uuid, liker_id uuid, listing_id uuid)
returns void
language plpgsql
as $$
declare
new_notification_id bigint;
begin
insert into notifications ("receiverId", "actorId")
values (receiver_id, liker_id)
returning id into new_notification_id;
insert into listingNotifications("notificationType", "notificationId", "listingId")
values (1, new_notification_id, listing_id)
end;
$$;
pvtctrlalt
09/18/2022, 8:11 PMcreate or replace function createticket("auth" text, "ticketname" text, "issuetype" text, "devicetype" text ,"issuedetails" text, "priority" text)
returns void
language plpgsql
security definer set search_path = public
as $$
BEGIN
IF (checkifauth(auth)) THEN
insert into public.tickets (id, ticketname, issuetype, devicetype, issuedetails,priority)
values (new.id,new.ticketname,new.issuetype,new.devicetype,new.issuedetails,new.priority);
END IF;
END;
$$
and this is my other function incase that has issues
BEGIN
IF EXISTS (select authkey from public.userprofile where authkey::text = auth) THEN
return true;
else return false;
END IF;
END;
and this is thw query i run
select createticket('0d06829a-d271-4dde-b69a-6d16a2254143','test','test','test','test','test');
edgaras
09/18/2022, 10:15 PMDanMossa
09/18/2022, 10:33 PMmessages
and rooms
.
This is the rooms
schemas:
CREATE TABLE rooms (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id_one uuid NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
user_id_two uuid NOT NULL REFERENCES users(user_id) ON DELETE CASCADE
);
messages
schema:
CREATE TABLE messages (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
from_user_id uuid NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
message text NOT NULL,
room_id integer NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,
create_time timestamp with time zone NOT NULL DEFAULT now(),
message_id uuid NOT NULL UNIQUE
);
I want to create an RLS policy on the messages table for SELECT
such that a user can only read messages for which they are either part of from_user_id
to to_user_id
.
This is what I have
SELECT m.room_id
FROM messages m
JOIN rooms r ON r.id = m.room_id
WHERE user_id_one = '8dd172ba-7cfc-4c43-a427-601e505709f6'
OR user_id_two = '8dd172ba-7cfc-4c43-a427-601e505709f6'
But how can I use my RPC function to match up with the valid room_id
CREATE FUNCTION get_rooms_with_user_id(p_user_id uuid)
Basically, I want to check that the only messages a user is getting is one where they are in that room.
Any ideas?Cory
09/18/2022, 11:39 PMBoogersLLC
09/19/2022, 12:35 AMinviteUserByEmail
mentions that it requires the service_role
key.
Based on the type definition, I don't understand how I would pass the service_role key to the function. Or maybe I'm misunderstanding how the service_role key is applied?
Also, for context, this is inside an edge function. So I believe I should have access to SUPABASE_SERVICE_ROLE_KEY
I just don't understand how to apply it.
javascript
const { data: user, error } = await supabaseClient.auth.api.inviteUserByEmail(
email,
);
jt
09/19/2022, 1:08 AMKickSquare
09/19/2022, 3:59 AMalx90
09/19/2022, 9:27 AMconst { data, error } = await supabase.storage
.from("mybucket")
.upload("public/avatar1.png", req.body.file);
Im getting this error response:
{
statusCode: '401',
error: 'Invalid JWT',
message: 'new row violates row-level security policy for table "objects"'
}
Im not set any policies. My policies are totally empty.
[UPDATE]: I executed this SQL query:
-- 1. Allow public access to any files in the "public" bucket
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'mybucket' );
Still the same error :/
Some ideas what to do ?lewisd
09/19/2022, 10:22 AMselect notifications.id, notifications.status, notifications."receiverId", notifications."notificationObjectId"
from
notifications
left join
"notificationObjects" on notifications."notificationObjectId" = "notificationObjects".id;
pvtctrlalt
09/19/2022, 12:32 PM(uid() = id)
and can only insert when authenticated. but when i send in an insert statement from my program i get code: '42501',
details: null,
hint: null,
message: 'new row violates row-level security policy for table "tickets"'
this was my function. the user is signed in
export async function createTicket(ticketdata:any) {
const { data, error } = await supabase
.from('tickets')
.insert([
{ devicetype: ticketdata.deviceType },
{ issuedetails: ticketdata.issueDetails },
{ issuetype: ticketdata.issueType },
{ priority: ticketdata.priority },
{ ticketname: ticketdata.ticketName },
], { returning: 'minimal' }, { upsert: true })
if (error) console.error(error)
else console.log(data)
}
Spoonz
09/19/2022, 1:22 PMB3n
09/19/2022, 1:47 PMSyniex
09/19/2022, 4:31 PMNin
09/19/2022, 4:35 PMconst { data: total } = await supabase
.from("tasks")
.select("id", { count: "exact", head: true });
console.log(total);
enti
09/19/2022, 4:37 PMjs
const { data, error } = await supabase
.from('users')
.upsert({ column_1: 'data1', column_2: 'data2' }, { onConflict: 'column_1' })
So for now, if there's a conflict on column_1, the query does nothing. But I want to update column_2 for that specific existing column_1 conflict instead.
The doc doesn't provide any detail. Do you know how I could provide this request though my supabase API call?pocin
09/19/2022, 4:41 PMsupabase.from().select().not('column', is, null)
https://supabase.com/docs/reference/javascript/notSahil Singla
09/19/2022, 5:11 PMgaryaustin
09/19/2022, 6:31 PMSimonP
09/19/2022, 6:05 PM{
"component": "api",
"error": "Unable to find email with Azure provider",
"level": "error",
"method": "GET",
"msg": "500: Error getting user email from external provider",
"path": "/callback",
"referer": "",
"remote_addr": "212.95.23.44",
"time": "2022-09-14T11:33:53Z",
"timestamp": "2022-09-14T11:33:52Z"
}
adek
09/19/2022, 6:11 PM