Search code examples
triggerssupabase

ERROR: record \"new\" has no field \"raw_user_meta_data\"


Event Message

{"component":"api","error":"failed to close prepared statement: ERROR: current transaction is aborted, commands ignored until end of transaction block (SQLSTATE 25P02): ERROR: record "new" has no field "raw_user_meta_data" (SQLSTATE 42703)","level":"error","method":"POST","msg":"500: Database error saving new user","path":"/signup","referer":"http://localhost:3000","remote_addr":"176.232.21.227","request_id":"8b6a13d9e53c0535-OTP","time":"2024-08-21T10:53:07Z"}

Is this about trigger ? why am i getting this error does anyone know

CREATE OR REPLACE FUNCTION handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
  INSERT INTO public.profiles (
    id, 
    username, 
    full_name, 
    avatar_url, 
    country, 
    province, 
    gender, 
    active
  )
  VALUES (
    NEW.id, 
    NEW.raw_user_meta_data->>'username', 
    NEW.raw_user_meta_data->>'full_name',
    NEW.raw_user_meta_data->>'avatar_url',
    NEW.raw_user_meta_data->>'country',
    NEW.raw_user_meta_data->>'province',
    NEW.raw_user_meta_data->>'gender',
    (NEW.raw_user_meta_data->>'active')::boolean
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql security definer;

Trigger

I found at that STATEMENT orientation causing this error, my orientation is already set to ROW.


Solution

  • Problem solved. I accidentally created another trigger that triggered directly profiles. I also have same trigger on Auth.users which is enough for this situation deleting profiles trigger solved my problem.