How do i reference user id in sql?
# help
l
How do i reference user id in sql?
n
Hello @limzee! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User role so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the /title command! We have solved your problem? Click the button below to archive it.
o
Hi Are you asking how you can link a user id (from private table) with a public table?
n
limzee (2022-05-03)
l
In the visual table editor i can reference to other schemas using the link button. I'm just wondering how I would do that in code.
@Olyno Does that make sense? 🙂
o
Oh so using the Js sdk right?
l
the sql editor
o
Aaaaaaaalright i got it (sorry i'm slow ahah)
So the syntax isn't right, that's why you have the error. Here is how to fix it:
Copy code
postgres
belongs_to uuid references auth.users(id)
This should work @limzee
The type was missing too
l
Alright tyvm ! 😄
s
you cannot reference auth user with public tables
You can use triggers

https://www.youtube.com/watch?v=0N6M5BBe9AEâ–¾

l
@Studywithdesign Okey so what I want to do is just restrict access to rows based on the currently authenticated user. Is this the way to go? Or would I even need a reference, wouldn't it be enough to just store the currently authenticated userid in a column? sorry i'm new to sql 🙂
s
You can rls

https://youtu.be/Ow_Uzedfohkâ–¾

l
@Studywithdesign Yea but I still need a reference to the user in the row then right?
thanks i'll check that out
s
Sorry, I just did a mistake. You can connect auth with public tables but it will suck later
So you need to make a profile table
If you are creating a dashboard then you can use rls easily
l
alright 🙂