https://supabase.com/ logo
Hey guys! I want to divide users in different grou...
# help
v
Hey guys! I want to divide users in different groups so that each group can check there records only, moreover groups can add members to there group, I'm searching, but no luck till now !
n
Hello @vMInvincible! 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.
g
v
Thank You, Will look into it 🙂
Hey can I authenticate users with a custom field, for example Username Password Department
g
If you mean pass in extra info... The main way to directly pass in info in one step is https://supabase.com/docs/reference/javascript/auth-signup#sign-up-with-additional-user-meta-data . Otherwise you have to update your "profile" table after you have successfully logged in.
v
Okay, Thank you will check it. 🙂
Actually, I want to use login details such as Department in order to connect the tables inside supabase, but I can't a find a way to do it.
g
You want to use department as part of your RLS?
v
No i want to use department a way to identify users which department they belong and i want to get it through login form details
g
OK, did you try the signUp with data option path? That would put the data in the auth.users table, then you can use a trigger function on that table to generate your own table in public schema.
v
Okay so the data option path ! Data is in meta data in auth.users how to use this meta.data in the login form !
Like we use for Username: inputfromuser password : inputfromuser Department: inputfromuser Then on the basis of department name he/she will have access to department ‘table’
If i’m confusing you ! I apologise in advance.
g
You take data from your login form fields and put it in the data object for the signUp call.
Copy code
const { user, session, error } = await supabase.auth.signUp(
  {
    email: 'example@email.com',
    password: 'example-password',
  },
  {
    data: { 
      username: 'John', 
      department: 'shipping',
    }
  }
)
v
Yes sir , i did it but there is no column of username or department in auth.users
Where are they stored ?
g
in the raw_user_meta_data column.
You would normally make a copy of your relevant data to another table so you can use it easier and control RLS on it. https://supabase.com/docs/guides/auth/managing-user-data#advanced-techniques
This is someone's function (not tested by me) that shows how to copy the metadata to another table when it is inserted into the auth.users table:
Copy code
create function public.handle_new_profile()
returns trigger as $$
begin
    insert into public.profiles (user_id, user_email, username)
    values (
    new.id,
    new.email, 
    new.raw_user_meta_data->>'username'
    );
    return new;
end;
$$ language plpgsql;

-- 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();
BUT anything coming from the client is not secure... so the user can change their department at anytime with some code.
v
Yes you are right ! I will think about it !
Thanks for your help and please don’t close this chat ! I will be in touch .
i don't see anything in it except {} .
g
Can you show your signUp call? And I assume you mean in your table, in my pix I don't have any user metadata.
hmmm is that .signUp and not .signIn?
v
signUP
g
Copy code
const {session,user,error} = await supabase.auth.signUp({
            email: 'gabbott@sxxxxxxx.com',
            password:'zzzzzzz2'
        },
            {data:{username:'gary'}
            }
            )
You are sending this to the API directly? I think that is wrong format for the body...
You don't want the extra {} around data if sending in the body directly. I'm not sure about the meta_security thing... this is what supabase-js sends out on the wire.
for sure drop the {} around data
v
which one exactly
data : "username" : "gg",
"department" : "CIS",
used this, same output
g
No.
Copy code
{ "email":"",
  "password":"",
  "data":{"username":"name","department":"CID"
}
v
okay will try it
g
The API tab on the dashboard is very useful for figuring out format for curl calls. Just click the bash tab. Here is .update() which shows the format for data
v
Copy code
{
  "email": "",
  "password": "",
  "data": {
    "username": "name",
    "department": "CID"
  }
}
g
Yes that is the body format, with email and password filled in.
v
finally
g
Using the rest API directly is a pain the butt.
v
hahaha true, but i'm starting to like it :P, thanks for your support
will be back xD
g
Probably should start a new topic for new questions, going to be in and out and other's won't look in a long thread.
v
okay will start. thanks
n
Thread was archived by @vMInvincible. Anyone can send a message to unarchive it.