ui
02/04/2023, 10:00 PMjdgamble555
02/04/2023, 10:21 PMauth.provider.google.enable
JDomcario
02/04/2023, 10:32 PMDisamDev
02/04/2023, 10:57 PMelliott
02/05/2023, 12:15 AMnateland
02/05/2023, 12:21 AMIsological
02/05/2023, 4:22 AMhirsh
02/05/2023, 5:54 AMGlop
02/05/2023, 6:43 AMgleb
02/05/2023, 9:12 AMtsx
const [supabase] = useState(() => createBrowserSupabaseClient<Database>())
return (
<SessionContextProvider supabaseClient={supabase} initialSession={pageProps.initialSession}>
<Provider store={store}>
<Layout>
<Component {...pageProps} />
</Layout>
</Provider>
</SessionContextProvider>
)
But now I wonder how to access supabaseClient
from the RTK Query endpoint. The problem is that RTKQ caches all queries in redux store, so they have to be serializable, therefore I can't pass client as query argument. I cannot use useSupabaseClient
directly in the RK Query code either either because it's a react hook.
I want my queries to look something like this:
ts
export const myApi = api.injectEndpoints({
endpoints: (build) => ({
getData: build.query<Result[], void>({
queryFn: async (arg, queryApi, extraOptions, baseQuery) => {
const supabase = ?????
const {error, data} = await supabase
.from("my_table")
.select("*");
if (error) {
return {error};
}
return {data};
}
}),
})
});
YokoWasis
02/05/2023, 9:24 AMDisamDev
02/05/2023, 9:56 AMuserId (type: uuid)
so I put auth.uid() = userId
but Supabase says to me that userId
doesn't exists.GKL
02/05/2023, 12:41 PMjs
const fetchClients = async () => {
try {
setLoading(true)
let { data: clients, error } = await supabase
.from('clients')
.select()
if (clients) {
setClients(clients)
}
} catch (error) {
console.log(error)
} finally {
setLoading(false)
}
}
and this is the code for my beats:
js
const fetchBeats = async () => {
try {
setLoading(true)
let { data: beats, error } = await supabase
.from('beats')
.select()
if (beats) {
setBeats(beats)
}
} catch (error) {
console.log(error)
} finally {
setLoading(false)
}
}
this is my beats table to show theres data in it (see the photo). whenever i do console.log(beats)
it just shows an empty arrayPoypoypoy
02/05/2023, 1:49 PMnelakay
02/05/2023, 3:33 PMhirsh
02/05/2023, 4:43 PM최지연
02/05/2023, 4:48 PMcorasan
02/05/2023, 4:49 PMpele'sghost
02/05/2023, 6:06 PMdeclare
new_times int;
begin
select total_times
into new_times
from public.place_eaten
where place_id = place_id;
new_times = new_times + 1;
update public.place_eaten
set total_times = new_times
where place_id = place_id;
return new_times;
end
This is where I am calling it in the client:
const addOne = async () => {
let { data, error } = await supabase.rpc('timesEaten', {place_id: choice.place_id})
setEatenPlusOne(data)
if (error) console.error(error)
else console.log(data)
}
After watching the increment video's on youtube, I am suspecting it might be the second where statement because it is adding one to the entire column for all the rows. Can anyone guide me in the right direction?jules
02/05/2023, 6:21 PMkevlust
02/05/2023, 6:28 PMShelby
02/05/2023, 6:56 PM.Volxen
02/05/2023, 8:50 PM0xSnakeDg.eth
02/05/2023, 9:34 PMadoublef
02/06/2023, 12:11 AMpgx
library to connect and while I am able to connect and insert/select
from a table on the public
schema when I try to make my own schema and perform the same actions I get a permission denied error.
Currently unsure if it's an issue with Supabase or the client library so trying my luck with both.Cory
02/06/2023, 12:24 AMmalachi
02/06/2023, 12:26 AMmohnish
02/06/2023, 1:19 AMzhay
02/06/2023, 1:47 AMjinsley8
02/06/2023, 8:50 AMsql
--- uid() function to be used in RLS policies
CREATE FUNCTION next_auth.uid() RETURNS uuid
LANGUAGE sql STABLE
AS $$
select
coalesce(
nullif(current_setting('request.jwt.claim.sub', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')
)::uuid
$$;
Shown here: https://next-auth.js.org/adapters/supabase#create-the-next_auth-schema-in-supabase
My JWT payload looks like this:
js
const payload = {
sub: user.id,
user: payloadUser,
aud: 'authenticated',
role: 'authenticated'
};
I need a new helper function that instead of using "sub", it uses user
which is an object to access user.address
(text id string).
I tried this but doesn't seem to work. on
sql
--- uid() function to be used in RLS policies
CREATE FUNCTION next_auth.eth() RETURNS text
LANGUAGE sql STABLE
AS $$
select
coalesce(
nullif(current_setting('request.jwt.claim.user.address', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'user.address')
)::text
$$;
Now I try to use (eth() = owner_of)
in a RLS policy and it shows Error updating policy: failed to update pg.policies with the given ID: function eth() does not exist