CREATE FUNCTION
  public.create_profile_for_new_user()
  RETURNS TRIGGER AS
  $$
  BEGIN
    INSERT INTO public.profiles (id, full_name, email)
    VALUES (
      NEW.id,
      NEW.raw_user_meta_data ->> 'user_name',
      NEW.email
    );
    RETURN NEW;
  END;
  $$ LANGUAGE plpgsql SECURITY DEFINER;