HAHZNFT
03/10/2023, 7:03 PMVik
03/10/2023, 7:27 PMfollowers
table to ensure that the use_id
and followee_id
can not be the same user ID. Meaning they can not be following or follow themselves. But with my current policy it still allows me to insert a row with those columns having matching IDs.cfofiu
03/10/2023, 7:33 PMSomGG
03/10/2023, 7:39 PMDeed
03/10/2023, 8:32 PMconst _showChannelPresence = supabase
.channel("show-presence")
.on("presence", { event: "sync" }, () => {
const state = _showChannelPresence.presenceState();
console.log(state);
}).subscribe();
Vik
03/10/2023, 9:27 PMfollowers
table.
The current structure for my followers
table goes like this:
Row: {
approved: boolean | null;
created_at: string;
follow_id: string;
followee_id: string;
user_id: string;
};
followee_id
and user_id
are composite keys that relate to the profiles.id
profiles
is setup like so:
Row: {
about: string | null;
avatar_url: string | null;
id: string;
joined: string;
location: string | null;
name: string | null;
onboarded: boolean;
private: boolean;
username: string;
};
The select policy that I'm working on should allow if:
auth.uid() = user_id
auth.uid() = followee_id
OR
The account is not private
OR
The account is private but an approved followers
row exists.
This is what I currently have but I'm getting an infinite query error. What am I doing wrong with the check?
(
(auth.uid() = user_id) OR
(auth.uid() = followee_id) OR
(
exists(
select 1 from profiles
where profiles.id = followee_id
and (profiles.private = false OR exists(
select 1 from followers
where followers.followee_id = profiles.id
and followers.user_id = auth.uid()
and followers.approved = true
))
)
OR
exists(
select 1 from profiles
where profiles.id = user_id
and (profiles.private = false OR exists(
select 1 from followers
where followers.followee_id = auth.uid()
and followers.user_id = profiles.id
and followers.approved = true
))
)
)
)
cagey
03/10/2023, 9:36 PMpermission denied for function crypto_aead_det_encrypt
when attempting to create a new pgsodium key. I can successfully add rows to the same table via the online SQL editor.
The relevant SQL is:
CREATE TABLE secret (
name TEXT NOT NULL,
account_id uuid NOT NULL,
key_id uuid NOT NULL REFERENCES pgsodium.key(id) DEFAULT (pgsodium.create_key()).id,
nonce bytea NOT NULL DEFAULT pgsodium.crypto_aead_det_noncegen(),
contents text NOT NULL,
CONSTRAINT fk_account FOREIGN KEY(account_id) REFERENCES account(id),
PRIMARY KEY(name, account_id)
);
SECURITY LABEL FOR pgsodium
ON COLUMN secret.contents
IS 'ENCRYPT WITH KEY COLUMN key_id NONCE nonce ASSOCIATED (name, account_id)';
habanero
03/11/2023, 12:35 AMgaryaustin
03/11/2023, 1:11 AMLukas
03/11/2023, 1:15 AMrobipop22
03/11/2023, 1:20 AMheedongcho-xyz
03/11/2023, 2:56 AMローリー Laurie
03/11/2023, 5:51 AMSTILLWATER;
03/11/2023, 10:09 AMjson
{"code":"21000","details":null,"hint":"Ensure that no rows proposed for insertion within the same command have duplicate constrained values.","message":"ON CONFLICT DO UPDATE command cannot affect row a second time"}
I have a code with onConflict of two columns so it doesnt insert duplicate and just updates it.
js
const { error: insertion_error } = await supabase_connect
.from('Contact')
.upsert(data, { onConflict: 'user_id,phonenumber' });
Pr. rootKitty
03/11/2023, 12:02 PMts
// Watchlist page, having all the favorites shows of the user (user.saved_shows)
const Watchlist = () => {
const user = useAuthStore((state) => state.user)
const [loaded, setLoaded] = useState(false)
useEffect(() => {
setLoaded(true)
console.log('User updated in component')
}, [user])
return (
<div className={styles.container}>
<Sidebar />
{loaded && (
<div className={styles.watchlistCardsContainer}>
{user?.saved_shows?.map((show) => (
<SavedShowCard key={show} showId={show} userId={user.id} />
))}
</div>
)}
</div>
)
}
export default Watchlist
ts
// User store
import { persist } from 'zustand/middleware'
import { supabase } from '@/utils/supabase'
import type { User } from '@/types/user.interface'
interface AuthStore {
user: User | null
setUser: (user: User | null) => void
signUp: (name: string, email: string, password: string) => Promise<void>
signIn: (email: string, password: string) => Promise<void>
signOut: () => Promise<void>
isLoaded: boolean
setIsLoaded: (isLoaded: boolean) => void
}
export const useAuthStore = create<AuthStore>()(
persist(
(set, get) => ({
user: null,
setUser: (user) => {
set(() => ({ user }))
console.log('User updated in store')
localStorage.setItem('user', JSON.stringify(user)) // Save user to local storage
},
...
What is confusing me is that the console log User updated in store gets triggered, while the console log User updated in component doesn't what am I missing ? 😮mahaveer
03/11/2023, 12:48 PMUSER
account or an ORGANIZATION
account and members
is the mapping table between different account types.
sql
create type "public"."account_type" as enum ('ORGANIZATION', 'USER');
create table "public"."accounts" (
"id" uuid not null default uuid_generate_v4(),
"created_at" timestamp with time zone default now(),
"slug" text not null,
"type" account_type
);
create table "public"."members" (
"id" uuid not null default uuid_generate_v4(),
"created_at" timestamp with time zone not null default now(),
"user_id" uuid not null references accounts(id),
"organization_id" uuid not null references accounts(id),
);
CREATE OR REPLACE FUNCTION public.check_members_constraint() RETURNS trigger LANGUAGE plpgsql AS
$function$BEGIN
IF (SELECT type FROM accounts WHERE id = NEW.user_id) <> 'USER' THEN
RAISE EXCEPTION 'user_id must reference an account with type = "USER"';
END IF;
IF (SELECT type FROM accounts WHERE id = NEW.organization_id) <> 'ORGANIZATION' THEN
RAISE EXCEPTION 'org_id must reference an account with type = "ORGANIZATION"';
END IF;
RETURN NEW;
END;$function$;
CREATE TRIGGER members_constraint_trigger BEFORE INSERT ON public.members FOR EACH ROW EXECUTE FUNCTION check_members_constraint();
When i run the following GQL query, how can i specify which column should be used to resolve the relation?
gql
{
accounts: accountsCollection {
edges {
node {
slug # <--- lets say this is account X
members: membersCollection {
edges {
node {
user_id
organization_id
accounts {
slug # <--- this is referring to the same account X how to tell supabase to resolve account with `organization_id` instead
}
}
}
}
}
}
}
}
redwookie
03/11/2023, 1:13 PMDean1
03/11/2023, 1:19 PMRaj Bennin
03/11/2023, 1:38 PMmogoatlhe
03/11/2023, 2:26 PMsetting up project
page which has been loading for over 40 minutes. I tried refreshing the page a few times but that didn't help.
Can someone please help.Benanna19
03/11/2023, 2:52 PMshawns2759
03/11/2023, 3:24 PMEK
03/11/2023, 3:24 PMif (isStreaming) {
eventSource = new EventSourcePolyfill(
'https://123123xpsdtmtk.functions.supabase.co/stream',
{
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
Authorization: 'Bearer ' + token,
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
},
}
)
I am trying to use data stream from a edge function, but I could not get it to work. It always threw a cors error. I tried the regular way of ``supabase.functions.invoke('stream')``' but it return data in a big chuck.nateland
03/11/2023, 3:57 PMnname
03/11/2023, 3:59 PMCaleb
03/11/2023, 6:16 PMDean1
03/11/2023, 7:08 PMEric
03/11/2023, 7:46 PMBEGIN;
ALTER POLICY "Places - Only authenticated users" ON "public"."places" USING (true);
COMMIT;
With no Bearer
token on my initial requests, api requests to this table correctly fail. Then, I log in and get a valid user response (and can see a session in the auth.sessions
table). My request to the table now succeeds correctly. However when I log out via the api (and see the row removed from the sessions table), I am still able to make API requests to the table. If I wait the TTL for the JWT, it expires as expected and API requests to the table fail properly.
My question:
- does the authenticated
policy check the JWT on the request to see if the user is authenticated or does it check the auth.sessions
table? I would expect a non-expired JWT to still fail if there is no active session.
- is there a way to enable RLS to check if the user in the JWT has an active session? does the authid helper method here https://supabase.com/docs/guides/auth/row-level-security#authuid check the JWT or the session user?Dean1
03/11/2023, 8:52 PMkillerthief
03/11/2023, 9:00 PMconst req = await axios.get("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQo2zi7aWGrKd8eTtROEbeG4noyYyEicLaqpMOmqXXN&s",{responseType:"arraybuffer"});
console.log(await req);
const imgBlob = new Blob([req.data],{"type": "image/jpeg"});
const imgUrl = URL.createObjectURL(imgBlob);
const Imagefile = new File([imgUrl],"imageGenerator.png",{type:"image/png"});
const d = new Date();
const time = d.getTime();
console.log(imgBlob);
console.log(Imagefile);
const {data,error} = await supabase.storage.from('images').upload(`${time}`,Imagefile,{cacheControl:'3600',upsert: false})
if(error === null){
const{data,error} = await supabase.storage.from('images').createSignedUrl(`${time}`,31563000)
console.log("Inner data of the signed url",data);
if(error === null){
const txnHashtoken = await (window as any).martian.createToken(collectionName, `${text}`, "keep it simple", 1,data, maxsupply)
console.log("Printing the hash token",txnHashtoken);
}
else{
console.log("Cannot create the signature URL ");
}
}
else{
console.log("Cannot upload the image");
}
js Above is the code . I have given an example like I am tryign to fetch an image from the url and store it in the supabase storage haven't been quite successful in it . Any clue anyone ?