0

I am trying to send confirmation email whenever user logged in for the first time, record its email to the table user_approvals table under public schema. so when i change the value of is_approved (boolean value by default value is false) to TRUE I am getting http schema does not exist. after manipulating few times as it was working earlier. user can directly access but don't receive any email. So for sending confirmation email am using RESEND api key and create function and trigger which executes successfully. after that when I change the value of is_approved I start facing that error only in case of from FALSE to TRUE. so for HTTP issue I enabled extension for that but still facing that.

CREATE OR REPLACE FUNCTION public.send_approval_email(user_email TEXT)
RETURNS VOID AS $$
DECLARE
api_key TEXT := 'Resend API key'; -- Replace with your actual Resend API key
response JSON;
BEGIN
-- Call the Resend API to send the email
response := (SELECT * FROM http.post(
'https://api.resend.com/emails',
json_build_object(
'from', ' sender email', -- Replace with your sender email
'to', user_email,
'subject', 'Your Account Has Been Approved',
'html', '

Congratulations! Your account has been approved.

'
),
ARRAY[http.header('Authorization', 'Bearer ' || api_key)]
));
-- Optionally, you can log the response or handle errors
RAISE NOTICE 'Email sent: %', response;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION public.notify_user_on_approval()
RETURNS TRIGGER AS $$
BEGIN
IF NEW.is_approved = TRUE AND OLD.is_approved = FALSE THEN
PERFORM public.send_approval_email(NEW.email);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Create the trigger on user_approvals
DROP TRIGGER IF EXISTS on_user_approval ON public.user_approvals;
CREATE TRIGGER on_user_approval
AFTER UPDATE ON public.user_approvals
FOR EACH ROW EXECUTE FUNCTION public.notify_user_on_approval();

ALTER ROLE authenticator WITH PASSWORD 'pass@123'; -- Change the password
ALTER ROLE authenticator SET pgrst.db_extra_search_path TO 'public, extensions'; -- Set the extra search path
ALTER SYSTEM SET pgsodium.enable_network = true; -- Enable network for pgsodium
SELECT pg_reload_conf(); -- Reload the configuration

enter image description here

enter image description here

enter image description here

enter image description here

I'm also new to supabase so tried multiple ways first tried to use my next js application to send confirmation with the help of RESEND library and its key but didnt work out. how can we use supabase function and triggers to send the email. so for i manually enabled http but still facing issue and tried network setting in database but still facing this issue

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.