These have all been answered, you can see one and ...
# help
s
These have all been answered, you can see one and two in the Supabase docs
Not sure how 3 would work since a UUID would not have been generated for the user as yet
I guess a way around 3 would be to make the primary key a different key than the uuid that comes from
auth.users
and then you could store that in the session, then when you call signUp, you pass this id along as a additional data and do an update on the table at that point to store the uuid from the
auth.users
table
It seems a bit of a weird workaround or way of doing this, maybe you if state your use case there could be suggested a different solution
r
Was typing a msg at the same time as you replied: any suggestions for implementations for #3? @User Our goal is basically allow our users to invite other users via phone number & send them a # of points, then we send the invited user a text telling them to download the app. --> Phone number is in a way our user's unique IDs. Currently the idea is we'd create a row in the public.users DB first with the # of points + their phone number, then somehow link when they actually sign up with that row that was created previously --> which I'm not sure how to do.
s
Ah that is a good use case for sure, let me think about it a little (just cooking dinner at the moment) and see how I can assist you with this
r
@User ^any updates?
hope you enjoyed your dinner lol
s
Will you be managing the part of sending the invite via phone number? because Supabase doesn't currently do this, they only handle invite by email
r
Ya we handle invite by phone number
@User is there anyway to generate the UUID for the user row before the user authenticated with auth.signUp? The problem is we're a fintech app so we're working with partners which need us to pass them a UUID first. So ideally we should pass the final UUID right away rather than putting some placeholder then changing it after
s
Not in the case of
auth.users
table, but this you could do in your own
public.users
table, since this would be created by you
r
hmm for proper authentication to happen my understanding is those uuids from auth.users & public.users must be synchronised right? Is this correct, & if it is, how would we make sure the auth.users UUID is the same as the pre-initilized public.users UUID?
s
No that's not entirely correct, you could use a different primary key for
public.users
while having a separate foreign key in the same table for
auth.users
r
is the default using the same primary key?
s
I'm not sure what you mean by default?
public.users
is a table that you create yourself, so there are no defaults
l
Hi, so I've been trying to create a public.users table from auth.users, but couldn't get the user's additional user meta data. new.id and new.email work perfectly.
Copy code
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id, email, first_name, last_name)
  values (new.id, new.email, PlaceholderA?, PlaceholderB?);
  return new;
end;
$$ language plpgsql security definer;
 
drop trigger if exists on_auth_user_created on auth.users;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
What should i be placing in PlaceholderA and PlaceholderB when I call the signUp function like this?
Copy code
// Calls signUp function from the context
    const { error } = await signUp(
      { email: email, password: password },
      {
        data: {
          first_name: firstName,
          last_name: lastName,
        },
      }
    );
just in case it's relevant, my create table SQL snippet looks like this
Copy code
-- USERS
DROP TABLE if exists public.users cascade;
create table public.users (
    id uuid references auth.users not null,
  email text,
  first_name text,
  last_name text,
    primary key (id)

);
 alter table public.users enable row level security;
s
l
Thanks for the prompt reply, I'm checking it now
so I tried to follow your example, and here is how the additional user meta data are passed in when a user sign up
Copy code
const { user, error } = await signUp(
      { email, password },
      {
        data: {
          first_name,
          last_name,
        },
      }
    );
here is how i'm inserting them into public.users
Copy code
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id, email, first_name, last_name)
  values (new.id, new.email,new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name');
  return new;
end;
$$ language plpgsql security definer;
 
drop trigger if exists on_auth_user_created on auth.users;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
but first_name and last_name are NULL in public.users
when i console.log user, it's showing user object with keys email and id, but user.user_medatada is an empty object
s
I can't tell what's wrong from this code, but if you look at the migrations in the link I sent you it should help and also you can look at the code to see how I'm adding the first name and so forth
l
Thank you, I'll try that