letourpowerscombine
11/10/2021, 4:53 PMprofiles
table when new users are added, including metadata like email address
, name
, website
, all through the initial sign up function. So creating a new user like this:
javascript
const { data, error } = await supabase.auth.signIn(
{ email: localStorage.getItem('email') },
{
data: {
full_name: formData.get('full_name'),
introduction: formData.get('introduction'),
website_url: formData.get('website_url'),
linkedin_url: formData.get('linkedin_url'),
twitter_handle: formData.get('twitter_handle'),
contact_method: formData.get('contact_method')
}
})
And handling it like this:
sql
create function public.handle_new_profile()
returns trigger as $$
begin
insert into public.profiles (user_id, user_email, full_name, introduction, website_url, linkedin_url, twitter_handle, contact_method )
values (new.id, new.email, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'introduction', new.raw_user_meta_data->>'website_url', new.raw_user_meta_data->>'linkedin_url', new.raw_user_meta_data->>'twitter_handle', new.raw_user_meta_data->>'contact_method');
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_profile();
Currently, new rows in profiles
are created when the function is called — but they only contain the user_id
and user_email
fields, none of the other data.
I feel like this might be some syntax error in the public.handle_new_profile()
function, not receiving the user metadata or int it the right way. Can anybody suggest a troubleshoot/fix?YelloJello
11/10/2021, 5:13 PMYelloJello
11/10/2021, 5:14 PMauth.users
table and looking at the raw_user_meta_data column to see if it's populatedYelloJello
11/10/2021, 5:14 PMselect * from auth.users
YelloJello
11/10/2021, 5:15 PMletourpowerscombine
11/10/2021, 5:25 PMselect * from auth.users
, I'm not seeing anything in the raw_user_meta_data column.letourpowerscombine
11/10/2021, 5:27 PMprofiles
, for when more of the application is ready later — instead of needing a separate form handler. Does that make sense? And any other thoughts on how I could do this?silentworks
11/10/2021, 5:45 PMsilentworks
11/10/2021, 5:45 PMmorenoto
11/26/2021, 12:13 AMuser_meta_data
but the correct name is raw_user_meta_data
!!!!morenoto
11/26/2021, 12:46 AMlanguage plpgsql security definer;
should not be there. It should be something like this:
-- inserts a row into public.users
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public.profiles (id)
values (new.id);
return new;
end;
$$;