Geoff
05/25/2023, 10:20 AMtenant_id
field (which is an integer) to the new user's app_metadata
, and I need to use this in row-level security policy.
I can't figure out the syntax for accessing this in the policy statement. I thought it would be something like this:
SQL
BEGIN;
ALTER POLICY "Enable tenant-based access" ON "public"."test" USING (tenant_id = (auth.jwt().app_metadata -> 'tenant_id'::integer));
COMMIT;
But I get a syntax error. Any ideas? Thanks!silentworks
05/25/2023, 10:32 AM->
should be ->>
instead.Geoff
05/25/2023, 10:41 AMtenant_id = (auth.jwt().app_meta_data ->> 'tenant_id')::integer
and this:
tenant_id = ((auth.jwt() ->> 'app_meta_data')::jsonb ->> 'tenant_id')::integer
The first gives a syntax error, the second is accepted but doesn't work. 😕SQL
tenant_id = ((auth.jwt()->>'app_metadata')::jsonb->>'tenant_id')::integer
silentworks
05/25/2023, 10:56 AM