Hi guys, if someone can help me out on this one it...
# help
z
Hi guys, if someone can help me out on this one it would be much appreciated. I am having issues with storing extra data on sign up from auth to public users table. On sign up i send extra data as:
Copy code
const { error, user } = await signUp(
    { 
      email, 
      password,
    }, 
    {
      data: { 
        accountType
      }
    });
i am using this trigger function to add user to public table
Copy code
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id, username, email, avatar_url)
  values (new.id, new.raw_user_meta_data ->> 'full_name', new.email, new.raw_user_meta_data ->> 'avatar_url');
  return new;
end;

$$ language plpgsql security definer;

-- trigger the function every time a user is created
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
Since the extra data is stored in auth user as user_metadata, how can i modify the upper trigger function to add this data in public users table. Thanks
s
hi guy new.raw_user_meta_data->>'avatar_url' i try custom trigger data -- This trigger can be pasted into the first init migration -- Copy from auth.users to public.users DROP FUNCTION IF EXISTS handle_new_user cascade; -- inserts a row into public.profiles table create or replace function public.handle_new_user() returns trigger as $$ begin insert into public.profiles ( id, full_name, avatar_url, nickname, matrial_status, gender, gender_indentity, cpf, birth_date, created_at ) values ( new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url', new.raw_user_meta_data->>'nickname', new.raw_user_meta_data->>'matrial_status', new.raw_user_meta_data->>'gender', new.raw_user_meta_data->>'gender_indentity', new.raw_user_meta_data->>'cpf', new.raw_user_meta_data->>'birth_date', current_timestamp ); return new; end; $$ language plpgsql security definer set search_path = public;