Adding Members to Organization with Teams Enabled
I am using the
organization
plugin with teams
enabled and am trying to add members to the organization/team via the addMember
API call:
I am trying this but when I inspect my database table, I do not see the teamId
being recorded into the database column. What am I missing?12 Replies
It seems the
addMember
function currently doesn't include the ability to specify a teamId
.
Hey @Ping , I'd be glad to make a pr to add teamId
to addMember
. Would that be okay?cc @bekacru
yeah go for it
Hey, I modified the
findTeamById
function in the org adapter to take in additional arguments. Does this look good to you, or would it be better to revert back to the original?
pr is ready for review, Let me know if the adapter method change looks good or if it should be reverted.
GitHub
feat(organization): Add teamId in addMember by Netrifier · Pull Req...
Added teamId option to addMember
await auth.api.addMember({
body: {
organizationId: <org_id>,
userId: <user_id>,
role: "admin",
...
Thank you for the PR!
is this member table schema from docs correct? If we are adding a member to a team, don't we need to specify the teamId in the member table as well?

yes, you need to add teamId in the member and invitations schema
Cool, thanks.
I had one more query, If I create a team inside an org, will org members be able to see all the teams or just the teams that they are a member of?
I want that team should ONLY be visible to the members of that team.
Other org members should not be able to see the teams they are NOT a part of. Is this possible with current implementation?
that would need to be handled at the application level as better-auth will only manage the auth
You can query the team which includes the user and display this to the user.
will try that, thanks
if you are using nextjs then you can check the team in the page component which will run on the server and pass the team to the rest of the components.