Add user with metadata to public users using functions

I use supabase functions and triggers to copy users to a public table. The function works fine until i try to add the metadata columns. Snippet shown below. Why would that be?

begin
  insert into public.users (id, email, first_name, last_name)
  values (new.id, new.email, new.raw_user_meta_data.first_name, new.raw_user_meta_data.last_name);
  return new;
end;


The code I use to sign up the user works just fine:
// sign up the user
const { data, error: e } = await locals.supabase.auth.signInWithOtp({
    email: body.email,
    options: {
        data: {
            first_name: body.first_name,
            last_name: body.last_name
        }
    }
});


The error that gets thrown looks like this:
"e": {
     "name": "AuthApiError",
      "message": "Database error saving new user",
      "status": 500
}


And I'm sure this isn't an RLS problem
Was this page helpful?