I want to be able to write a function in TypeScript and have it run when a user is created (probably when an insert event occurs on the auth table)
I don’t want to author this in plpgsql
How would I do this?
There are two possible approaches:
CREATE OR REPLACE FUNCTION public.telegram_on_new_user()
RETURNS trigger
security definer
set search_path public, auth, extensions
LANGUAGE plpgsql
AS $$
BEGIN
-- Passing the email address to the function
PERFORM http_get('https://xxxx.functions.supabase.co/telegram-bot?email=' || new.email);
RETURN NEW;
END;
$$;
CREATE TRIGGER new_user_trigger
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE public.telegram_on_new_user();
You can read more about how to create webhooks in Supabase in my blog.