Signup with additional metadata

Hey, I've also posted this yesterday and got a tip but doesn't work.

I have the Users table (The default one)
And a profile table with the following fields:
id, firstName, lastName, email, registeredToExam, paymentId
All of them are nullable except ID so I dont get errors at write

I have the following function put in place and the trigger:

create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
  insert into public.profiles (id, email, lastName, firstName)
  values (new.id, new.email, new.raw_user_meta_data->>'lastName', new.raw_user_meta_data->>'firstName');
  return new;
end;
$$;

-- trigger the function every time a user is created
drop trigger if exists on_auth_user_created on auth.user;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

During the signup I send the following data:

  const { user, error } = await supabase.auth.signUp(
    {
      email,
      password,
    },
    {
      data: {
        lastName,
        firstName,
      },
    }
  );

I made sure to validate the first and last name before I do this. yet, I get an error when creating the db, but I don't know why..

error in createUser { message: 'Database error saving new user', status: 500 } 

Id really need some help here
Was this page helpful?