© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Gn☆rby

Passing variables to RPC for RLS

Does Supabase have a way inbuilt that allows setting session variables when making PGSQL rpc calls?

My goal:
1. Use an RPC call
2. Pass _data to it, but also some other values that are used for authentication
3. RLS checks these auth values and says ya or nay

I found a method that worked by passing raw SQL but am concerned about SQL injection risk.

Le me know if there's a better way to do this? For reference, the auth is with a third party app that stores hashed values in a DB, and we can't use supabase auth to validate this.

Edited to include example RLS:
(account IN (
SELECT table1.account
FROM table1
WHERE ((NOT ((table1.key1)::text IS DISTINCT FROM COALESCE(current_setting('app.authvalue1'::text, true), 'undefined'::text)))
AND ((NOT ((table1.key2)::text IS DISTINCT FROM COALESCE(current_setting('app.authvalue2'::text, true), 'undefined'::text)))
OR (NOT (table1.key3 IS DISTINCT FROM COALESCE(current_setting('app.setting3'::authvalue3, true), 'undefined'::text))))))
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Allow RPC only for RLS query
SupabaseSSupabase / help-and-questions
4y ago
enforcing security through RLS vs RPC
SupabaseSSupabase / help-and-questions
2mo ago
passing json as parameter to rpc – size limit?
SupabaseSSupabase / help-and-questions
4y ago
Passing Supabase ENV variables to the migrations file
SupabaseSSupabase / help-and-questions
14mo ago