You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am implementing a very common scenario for a multi-tenant SaaS application where users can sign up by providing their email and password. The flow involves the following steps:
A tenant is created for the user upon registration.
A user is created for that tenant with the provided email and password.
An email verification is sent to the user to verify their account.
However, I am encountering a NullReferenceException during Step 2 when creating a user
var result = await _userManager.CreateAsync(user, request.Password);
What I Need Help With:
Guidance on how to properly ensure the tenant context is set up before invoking _userManager.
Any suggestions on debugging why _userManager or its dependencies might be null.
Best practices for handling this type of tenant and user creation flow.
Hi, there are two approaches you can go with here:
after registration and tenant creation redirect to a page to finish the setup -- in the redirected request the tenant should get picked up accordingly so the UserManager gets the correct database connection.
create a new DI scope from the RequestServices service provider on HttpContext, get an instance of IMultiTenantContextSetter from it, use it to set the tenant, then resolve an instance of UserManager from the new scope and it should have the correct tenant AppIdentityDbContext.
See if that helps and if you run into more issues let me know.
Hello, I am implementing a very common scenario for a multi-tenant SaaS application where users can sign up by providing their email and password. The flow involves the following steps:
A tenant is created for the user upon registration.
A user is created for that tenant with the provided email and password.
An email verification is sent to the user to verify their account.
However, I am encountering a NullReferenceException during Step 2 when creating a user
var result = await _userManager.CreateAsync(user, request.Password);
What I Need Help With:
Guidance on how to properly ensure the tenant context is set up before invoking _userManager.
Any suggestions on debugging why _userManager or its dependencies might be null.
Best practices for handling this type of tenant and user creation flow.
Extras
services.AddMultiTenant()
.WithHeaderStrategy("X-Tenant")
.WithEFCoreStore<TenantDbContext, TenantInfo>();
public class TenantDbContext : EFCoreStoreDbContext
{
public TenantDbContext (DbContextOptions options) : base(options)
{
}
}
public class AppIdentityDbContext : MultiTenantIdentityDbContext
{
public AppIdentityDbContext (IMultiTenantContextAccessor multiTenantContextAccessor, DbContextOptions options) : base(multiTenantContextAccessor, options)
{
}
public ZerpIdentityDbContext(IMultiTenantContextAccessor multiTenantContextAccessor) : base(multiTenantContextAccessor)
{
}
}
[MultiTenant]
public class AppIdentityUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
The text was updated successfully, but these errors were encountered: