Adamo
08/16/2021, 2:41 PMtypescript
const { user, error } = await supabase.auth.signUp({ email, password });
How would I go about attaching a username to the newly created user? I'm pretty confused about how the API works.
I have a 'profiles' table that was created from the User Management
starter, and I tried calling this after creating the user, which doesn't seem to work.
typescript
await supabase.from('profiles').update({ username }).eq('id', user?.id);
Scott P
08/16/2021, 2:47 PMusername
and user?.id
are (just console.log them to see).
If I was to guess, I'd say that user?.id
is undefined or null, but I can't be 100% sure.Adamo
08/16/2021, 2:50 PMScott P
08/16/2021, 3:25 PMconst {error, data} = await supabase.from('profiles').update({ username }).eq('id', user?.id);
What do you get returned?Adamo
08/16/2021, 4:19 PMid
and username
set right?Scott P
08/16/2021, 4:25 PMupdate
a row which doesn't exist. The row needs to exist before update will work.
The easiest way to handle this automatically is to create a trigger to create the record in the public.profiles
table. This example (https://github.com/supabase/supabase/discussions/306#discussioncomment-138424) should help, though you'll need to replace public.users
with public.profiles
.Adamo
08/16/2021, 4:25 PMauth.update
id
not foundprofiles
Scott P
08/16/2021, 4:31 PMAdamo
08/16/2021, 4:32 PM.upsert
instead of .update
.upsert
on the profile after with username/userId workedtypescript
const { user, error } = await supabase.auth.signUp({ email, password });
if (error) throw error;
const updates = {
id: user?.id,
username,
};
let { error: updateError, data } = await supabase
.from('profiles')
.upsert(updates, {
returning: 'minimal',
});
if (updateError) throw updateError;