SupabaseS
Supabase2y ago
e.mc

Accessing anon_key or url from sql

@

Hi there!

I have the following function and trigger definitions:

CREATE OR REPLACE FUNCTION handle_insert() RETURNS TRIGGER AS $$
BEGIN
    PERFORM net.http_post(
            url:='<WOULD BE NICE TO ACCESS SUPABASE_URL HERE>',
            body:=json_build_object('target',NEW.data)::jsonb,
            headers:='{"Content-Type": "application/json", "Authorization": "Bearer <NEED_TO_ACCESS_SENSITIVE_KEY_HERE>"}'::jsonb
    );
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER some_insert BEFORE INSERT OR UPDATE ON public.sometable
    FOR EACH ROW EXECUTE FUNCTION handle_insert();


I'm wondering what the best practice is for accessing these secrets within sql?

I would like to version control these function and trigger definitions but I don't want to expose them unnecessarily.

Thanks in advance!
Was this page helpful?