Open Closed

Admin user not created when tenant is created. #2240


User avatar
0
bolenton@gmail.com created

When I create a tenant, it does not create a admin user, am I missing somthing?


3 Answer(s)
  • User Avatar
    1
    jkrause created

    Hi bolenton,

    (Note: Making some assumptions here about the version of ABP that you are using, so I am going to assume v4.4 or v5.0 for the sake of my answer)

    Disclaimer: Though my answer may work for your particular case, please don't view this as an official response from Support nor the proper and/or intended work-around to address this particular issue.

    Whenever you create a new Tenant, there is an event handler class that is fired inside your project/module: AcmeTenantDatabaseMigrationHandler (where Acme is your project/module name).

    Inside this class there is a method sequence that is being called whenever a new Tenant is created:

    public async Task HandleEventAsync(TenantCreatedEto eventData)

    This is called when you create a Tenant from inside the SaaS management screens. Inside it makes a call to the MigrateAndSeedForTenantAsync method that does a few things:

    1. Try to apply migrations to the target database in case the Tenant used a dedicated database
    2. Seed the default admin user to the newly created Tenant

    There seems to be however a small issue, though perhaps unrelated, when [v] Use Shared Database is used, the code should not try to find an associated connection string for the newly created Tenant. When it cannot find the connection string, it tries to resolve an invalid database connection, which subsequently times out.

    Though personally not sure how it fixes it, inside the MigrateAndSeedForTenantAsync method you can see the usage of the Unit of Work that is responsible for commiting your Tenant admin user:

    // Seed data
    using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
    {
        await _dataSeeder.SeedAsync(
            new DataSeedContext(tenantId)
                .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
        );
    
        await uow.CompleteAsync();
    }
    

    Here you can see that requiresNew: true is being used, which if I understand it correctly, launches a new Unit of Work, which then cannot resolve the connection string of the current Tenant, and failes (due to time out). By settings this value to false, the "current" connection string of the existing Unit of Work is used, and thus the admin user is created as expected.

    using (var uow = _unitOfWorkManager.Begin(requiresNew: false, isTransactional: true))

    Hope this helps.

  • User Avatar
    0
    bolenton@gmail.com created

    @jkrause Thanks you so much the thoughtful and clear explanation! Yes you are right I am using 5.0rc. Changing "requiresNew" to false solve my issue!

    I understand the chan of event in this method sequence, though I do not understand why it would try to check for a connectionString since I am using a shared DB. I guess this is a bug?

    Thanks again so much for talking the time to help me out, that was a really helpful explanation.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    When it cannot find the connection string, it tries to resolve an invalid database connection, which subsequently times out.

    Can you share the error logs or some details? If this problem exists, we have to fix it.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11