S
Supabase4mo ago
In&Out

auth.uid() question

Hey folks, im trying to make something alone with pure pgsql, and i am wondering, how to make own auth.uid(), something that will have same functionality
11 Replies
garyaustin
garyaustin4mo ago
Not sure what you are asking for. auth.uid() is a postgres function. The code is in the repositories, but it basically just reads settings set by the PostgREST API server which gets the user id from decoding the JWT.
In&Out
In&OutOP4mo ago
oh, okay, i wanted to do same thing but in pure pgsql, do you know maybe how to do that, or some pointers to making it
garyaustin
garyaustin4mo ago
I don't know what pure pgsql means. What are you trying to do that auth.uid() won't work for you? Are you saying you want to just use the direct/pooler ports to run SQL and not use the REST API's?
In&Out
In&OutOP4mo ago
normal postgresql
garyaustin
garyaustin4mo ago
If so there is no JWT to decode. So you just use filters normally as part of your SQL query. If you want to use RLS then it is much more complicated as you will need to set up Postgres roles that obey RLS, figure out how to set a setting in part of your SQL transaction including the user id, role, etc.
In&Out
In&OutOP4mo ago
im kinda forced to use normal postgresql in tournament so thats why i ask lol, and im just trying to copy what supabase does as i have no idea how pgsql is ah i see i see
garyaustin
garyaustin4mo ago
You can't as auth.uid() and auth.jwt() depend on an external server decoding the JWT and setting the Postgres role and some settings. You can simulate that by doing several SQL operations before each of your queries to set those things and even still have auth.uid() work. But it is a bit painful.
garyaustin
garyaustin4mo ago
This drizzle code I found on a quit hit does some of that before each query...
No description
In&Out
In&OutOP4mo ago
can you send me the link please
garyaustin
garyaustin4mo ago
Drizzle ORM - Row-Level Security (RLS)
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
In&Out
In&OutOP4mo ago
thanks man sorry for much annoying questions lol

Did you find this page helpful?