Hi, I'd like to ask about syncing user. I'm using ...
# general
b
Hi, I'd like to ask about syncing user. I'm using .NET SDK in my multi-tenant application. However, I can't seem to find any tenant related attributes in the request body. When user is created, it's not assigned to any tenant. Is it possible to assign user to a tenant in this one request? Reference (https://docs.permit.io/sdk/nodejs/user/sync-user/, https://docs.permit.io/how-to/sync-users/)
d
Hi @Bintang Adinandra, yes it is possible 🙂 Lets see what @Ask Inkeep recommends
a
Thanks for tagging me @david. I'll look through relevant sources and get back to you shortly.
Yes, you can assign a user to a tenant during creation using the .NET SDK's
SyncUser
function. (1) When syncing a user, you can include
role_assignments
in the user object to immediately associate them with a role and tenant. (2) The payload structure supports this:
Copy code
var userObj = new UserCreate{
  Key = "key",
  Email = "<mailto:email@example.com|email@example.com>",
  First_name = "John",
  Last_name = "Smith",
  Attributes = {}
};
(1) To assign the user to a tenant with a role during creation, include the
role_assignments
field in your request. (2) This allows you to streamline the user creation process by immediately associating them with the appropriate role and tenant. If you create the user without role assignments, they will appear in the Directory under
All Tenants
. You can then assign roles to users to link them to specific tenants. Users are assigned to tenants via a role. (3) To indicate a resource instance belongs to a tenant, provide the tenant key (or id) as part of the resource object when calling permit.check() .
To learn more, see the sources I considered: [[1] SyncUser](https://docs.permit.io/sdk/dotnet/user/SyncUser) [[2] Sync your First User](https://docs.permit.io/overview/sync-your-first-user-with-sdk) [[3] Multi-Tenant Authorization](https://docs.permit.io/concepts/multi-tenant-authorization)
Thanks for the feedback, glad I was helpful.