Hey! Used `User Management Starter` but in `public...
# help
s
Hey! Used
User Management Starter
but in
public.profiles
table: supabase does not save the
user.user_metadata.username
, it saves e-mail for username. Any idea how to solve it?
n
Hello @schwarzsky! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
🆕 User Management Starter username saving wtriggers
g
This message found in search above might help: https://discord.com/channels/839993398554656828/869405720934744086/963989721707593768 But it would help if you showed the code being used to insert into the public.profiles table. I do not know without searching what or where "user management starter" is.
n
User Management Starter username saving wtriggers
s
Sorry
Copy code
js
       const { error, data } = await supabase.auth.signUp({
          email: email,
          password: password
        }, {
          data: {
            username: username
          }
        })
, just registering user with supabase auth, "user management starter" is in SQL Editor.
Copy code
-- Create a table for Public Profiles
create table profiles (
  id uuid references auth.users not null,
  updated_at timestamp with time zone,
  username text unique,
  avatar_url text,
  website text,

  primary key (id),
  unique(username),
  constraint username_length check (char_length(username) >= 3)
);

alter table profiles
  enable row level security;

create policy "Public profiles are viewable by everyone." on profiles
  for select using (true);

create policy "Users can insert their own profile." on profiles
  for insert with check (auth.uid() = id);

create policy "Users can update own profile." on profiles
  for update using (auth.uid() = id);

-- Set up Realtime!
begin;
  drop publication if exists supabase_realtime;
  create publication supabase_realtime;
commit;
alter publication supabase_realtime
  add table profiles;

-- Set up Storage!
insert into storage.buckets (id, name)
  values ('avatars', 'avatars');

create policy "Avatar images are publicly accessible." on storage.objects
  for select using (bucket_id = 'avatars');

create policy "Anyone can upload an avatar." on storage.objects
  for insert with check (bucket_id = 'avatars');

create policy "Anyone can update an avatar." on storage.objects
  for update with check (bucket_id = 'avatars');
g
Somewhere there should be an insert trigger on auth.users that calls a Postgres function. That function would take data from the auth.users insert and insert it into profiles table. OR maybe that starter just assumes the user makes a client call to insert to the profile table directly and does not rely on the data field in auth.users....
s
Looking into it 👀