SupabaseS
Supabaseβ€’3mo ago
Light

Can't get auth trigger working

I can't seem to get the auth trigger working... I feel like an idiot and I see that a lot of other people are running into the same issue as me.

I tried checking out some of the solutions on here, and I tried following the example from your YouTube channel, but I'm having no luck. No errors, no nothing... I don't even know how to debug this
Video I referenced - https://www.youtube.com/watch?v=tNhg-DhvyC8&

This is the code I was trying to use:
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
  INSERT INTO public.profiles (id, email, full_name, avatar_url)
  VALUES (
    NEW.id,
    NEW.email,
    COALESCE(NEW.raw_user_meta_data->>'full_name', NEW.raw_user_meta_data->>'name', split_part(NEW.email, '@', 1)),
    NEW.raw_user_meta_data->>'avatar_url'
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();


Any help would be greatly appreciate and I'm sorry for this repeated question. Clearly this is an issue a lot of people are having so maybe there is an easier way?
Was this page helpful?