I'm running into errors inside my `create_profile_...
# help
r
I'm running into errors inside my
create_profile_for_user
Postgres function when I try to access the
user_metadata
object on my newly signed up user. My
profiles
table has a
username
column (text) and my Postgres function looks like this:
Copy code
begin
  insert into public.profiles(id, username);
  values(new.id, new.user_metadata.username);
  
  return new;
end;
I'm adding
user_metadata
as per the docs: https://supabase.com/docs/reference/javascript/auth-signup#sign-up-with-additional-user-meta-data I know the data is successfully passed to the function because I can set
username
to
new
(instead of
new.user_metadata.username
or
new.data.username
or
new.username
or other similar attempts) and I get something like this entered into the
username
cell:
Copy code
(00000000-0000-0000-0000-000000000000,3a8b9bf6-3313-4ad6-b67f-8b9eb97f5874,authenticated,"",test@email.com,$2a$10$tXkm/RwqkSgKwuy5QbvCGuwRjuSSrU/YVus.4VkwNzIbAB5.OKhyO,,,"",,"",,"","",,,"{""provider"": ""email"", ""providers"": [""email""]}","{""username"": ""my cool username""}",f,"2022-01-04 03:39:06.055591+00","2022-01-04 03:39:06.055591+00",,,"","",,,"",0)
I'm new to Postgres, but I figure my attempt to access
user_metadata
with dot notation is what's failing me, does that sound right?
I took a look at the
users
table in the
auth
tab/database of my table editor to find a
raw_user_meta_data
column from which I am now copying into my
profile
table when a user signs up. Now I'm wondering how to deal with JSONB in order to just store the value instead of the whole object—see ya soon, haha!
Welp, its as simple as:
Copy code
begin
  insert into public.profiles(id, username);
  values(new.id, new.raw_user_meta_data->>'username');
  
  return new;
end;
Neat!