mikebarkmin
10/15/2021, 3:16 PMjs
supabase.from("user_public").select("*, contents:user_uploaded_contents(*)")
If you are getting a could not find a relationship, be sure to add a foreign key on the user_uploaded_contents table for the user_public table.AlanK
10/16/2021, 2:12 AMMyNameIsRickZero
10/16/2021, 4:14 AMEryou Hao
10/16/2021, 4:52 AMInvalid authentication credentials
in Nest.js, when performing select.
The createClient I executed in Nest.js uses the session after the user has logged in.
Is there something wrong with me?Eryou Hao
10/16/2021, 5:18 AMconst sbToken = req.cookies['sb:token']
supabase.auth.setAuth(sbToken)
mikebarkmin
10/16/2021, 7:03 AMmikebarkmin
10/16/2021, 7:04 AMts
export const signOut = async () => {
await supabase.auth.signOut();
await fetch("/api/account/auth", {
method: "POST",
headers: new Headers({ "Content-Type": "application/json" }),
credentials: "same-origin",
body: JSON.stringify({ event: "SIGNED_OUT" }),
});
};
export const signIn = async (email: string, password: string) => {
const { data, error, session } = await supabase.auth.signIn({
email,
password,
});
await fetch("/api/account/auth", {
method: "POST",
headers: new Headers({ "Content-Type": "application/json" }),
credentials: "same-origin",
body: JSON.stringify({ event: "SIGNED_IN", session }),
});
if (error) {
console.error(error.message);
throw error;
}
return data;
};
cataxcab
10/16/2021, 11:17 AM- First API call to insert book and get ID
- Second API call to insert genre and get ID
- Third API call to insert book-genre relation
This is what I can think of, but 3 API calls seems wrong.
Is there a way where I can do insert into these 3 tables with a single API call from my client?
Imagecataxcab
10/16/2021, 11:18 AMDeleted User
10/16/2021, 12:24 PMYogurtDrinker
10/16/2021, 12:45 PMawait supabaseClient.from('Udemy')
.select()
.contains('title', ['html']);
YogurtDrinker
10/16/2021, 12:45 PMGEThttps://wtccvsqohflpzaqdjzdn.supabase.co/rest/v1/Udemy?select=*&title=cs.{html}
[HTTP/2 404 Not Found 16ms]
Object { error: {…}, data: null, count: null, status: 404, statusText: "Not Found", body: null }
YogurtDrinker
10/16/2021, 12:49 PMtextSearch()
cataxcab
10/16/2021, 12:57 PMYogurtDrinker
10/16/2021, 1:19 PMtextSearch
which works but not exactly.
If i search for scrum
it worksYogurtDrinker
10/16/2021, 1:20 PMscrum master
it doesn't return any resultYogurtDrinker
10/16/2021, 1:21 PMmikebarkmin
10/16/2021, 1:58 PMsql
CREATE OR REPLACE FUNCTION public.upsert_flow(flow json)
RETURNS uuid
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
node json;
BEGIN
INSERT INTO flows (id, user_id, name, zoom, position, language, description, visibility, draft) VALUES(
($1->>'id')::uuid,
auth.uid(),
($1->>'name'),
($1->>'zoom')::bigint,
($1->>'position')::jsonb,
($1->>'language')::allowed_language,
($1->>'description'),
($1->>'visibility')::visibility,
($1->>'draft')::boolean
)
ON CONFLICT (id) DO
UPDATE SET
name=COALESCE($1->>'name', flows.name),
zoom=COALESCE(($1->>'zoom')::bigint, flows.zoom),
position=COALESCE(($1->>'position')::jsonb, flows.position),
language=COALESCE(($1->>'language')::allowed_language, flows.language),
description=COALESCE(($1->>'description'), flows.description),
visibility=COALESCE(($1->>'visibility')::visibility, flows.visibility),
draft=COALESCE(($1->>'draft')::boolean, flows.draft);
DELETE FROM flow_nodes WHERE flow_id = ($1->>'id')::uuid;
FOR node IN SELECT * FROM json_array_elements($1->'nodes') LOOP
INSERT INTO flow_nodes (id, position, data, type, flow_id)
VALUES (
(node->>'id')::uuid,
(node->>'position')::jsonb,
(node->>'data')::jsonb,
(node->>'type')::flow_node_types,
($1->>'id')::uuid
)
ON CONFLICT (id) DO
UPDATE SET
position=(node->>'position')::jsonb,
data=(node->>'data')::jsonb,
type=(node->>'type')::flow_node_types;
END LOOP;
RETURN $1->>'id';
END;
$BODY$;
cataxcab
10/16/2021, 2:12 PMmikebarkmin
10/16/2021, 2:13 PMts
export const upsertFlow = async (
id: string,
flow: Flow &
Pick<
definitions["flows"],
"draft" | "visibility" | "language" | "description"
>,
userId?: string
) => {
const [data] = await supabase
.rpc<string>("upsert_flow", { flow: decamelize({ id, ...flow, userId }) })
.single()
.then(handleSupabaseError);
return data;
};
I like to work in JavaScript with camelCase and in supabase with snake_case, therefore the decmelize function.cataxcab
10/16/2021, 2:30 PMLio
10/16/2021, 9:30 PMmikebarkmin
10/17/2021, 7:53 AMLio
10/17/2021, 8:31 AMerik_flywheel
10/17/2021, 11:16 AMsilentworks
10/17/2021, 11:54 AM~emma~
10/18/2021, 1:29 AMlocalhost:3000
. But, of course, I don't want to use localhost
on my deployed app.
Currently I am just switching between the two urls (localhost of prod) in Auth > Settings > Site URL. This is kinda painful, and obviously won't work once anyone other than me uses this thing. So how are people getting around this? Thanks in advance!khacvy
10/18/2021, 2:49 AMXzeta
10/18/2021, 2:50 AM~emma~
10/18/2021, 3:14 AM