79377565

Date: 2025-01-22 11:43:47
Score: 4
Natty:
Report link

Can you show the definition for your profiles table? I also ran into issues when setting triggers up and it ended up being something small that just needed to be tweaked.

if you check the logs it will usually throw an error you can see what it's complaining about. If you want, you can adjust the function to log an error so you can see what the problem is.

CREATE OR REPLACE FUNCTION handle_new_user() RETURNS trigger AS $$
BEGIN
    INSERT INTO profiles (id, full_name, avatar_url)
    VALUES (
        new.id, 
        new.raw_user_meta_data->>'full_name', 
        new.raw_user_meta_data->>'avatar_url'
    )
    ON CONFLICT (id) DO NOTHING;  -- This will ignore the insert if the id already exists

    RETURN NEW;
EXCEPTION
    WHEN OTHERS THEN
        RAISE WARNING 'An error occurred while handling the new user: %', SQLERRM;
        RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE handle_new_user();

There's no reason why the code above shouldn't work as long as you have a profiles table with an id, full_name and avatar_url field. If its still not working then definitely check the logs to see why.

Hope this helps!

Reasons:
  • Blacklisted phrase (2): still not working
  • Whitelisted phrase (-1): Hope this helps
  • RegEx Blacklisted phrase (2.5): Can you show
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Can you
  • Low reputation (1):
Posted by: cheekyprogrammer