peltops / e-imunisasi

2 stars 2 forks source link

Perubahan handle new user di supabase eimunisasi #189

Closed rfaturriza closed 1 month ago

rfaturriza commented 1 month ago

Perubahan function handle_new_user_2()

from:

begin insert into public.profiles (user_id, avatar_url) values (new.id, new.raw_user_meta_data->>'avatar_url'); return new; end;

to:

BEGIN IF NOT EXISTS (SELECT 1 FROM public.profiles WHERE user_id = new.id) THEN INSERT INTO public.profiles (user_id, avatar_url) VALUES (new.id, new.raw_user_meta_data->>'avatar_url'); END IF; RETURN new; END;

Perubahan after INSERT -> after UPDATE

select * from information_schema.triggers;

DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;

CREATE TRIGGER on_auth_user_created AFTER UPDATE ON auth.users FOR EACH ROW EXECUTE FUNCTION handle_new_user_2();