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 functionality11 Replies
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.
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
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?
normal postgresql
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.
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
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.
This drizzle code I found on a quit hit does some of that before each query...

can you send me the link please
Drizzle ORM - Row-Level Security (RLS)
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
thanks man
sorry for much annoying questions lol