Open Closed

Extending Tenant Management Entity #4610


User avatar
0
balessi75 created

ABP 7.0.1 Commercial / Blazor Server / EF / Separated IDS / Non-tiered

Hi,

We are following the exact steps in the following blog post: https://blog.antosubash.com/posts/abp-extend-tenant-with-custom-host

The CustomTenantRepository in the example has the following method:

 public async Task<Tenant> GetTenantByHost(string host, CancellationToken cancellationToken = default)
    {
        var context = await GetDbContextAsync();
        var tenant =  context.Tenants.Where(u => EF.Property<string>(u, "Host") == host);
        return await tenant.FirstOrDefaultAsync(cancellationToken: cancellationToken);
    }

The problem we are having is that the context.Tenants.Where method appears to be querying the table AbpTenants instead of SaasTenants. The following SQL Server exception occurs: Invalid object name 'AbpTenants'.

Please advise. Thank you in advance.


7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Because the pro template use the Saas module instead of Tenant, you can try:

    public class CustomTenantRepository : EfCoreRepository<SaasDbContext, Tenant, Guid>, ICustomTenantRepository
    {
        public CustomTenantRepository(IDbContextProvider<SaasDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
    
        public async Task<Tenant> GetTenantByHost(string host, CancellationToken cancellationToken = default)
        {
            var context = await GetDbContextAsync();
            var tenant =  context.Tenants.Where(u => EF.Property<string>(u, "Host") == host);
            return await tenant.FirstOrDefaultAsync(cancellationToken: cancellationToken);
        }
    }
    
  • User Avatar
    0
    balessi75 created

    Thanks @liangshiwei ! That was exactly the problem.

    I have another question though relating to this were we are creating a custom tenant resolver that resolves based on subdomain.

    Using https://blog.antosubash.com/posts/abp-extend-tenant-with-custom-host We now have the tenant properly being resolved based on subdomain, but every redirect goes back to the main domain without the tenant's current subdomain in the URL.

    I'm assuming the redirect information is coming from appsettings.json's "App:SelfUrl" and/or "App:RedirectAllowedUrls" settings. How can the system be aware of the tenant subdomain in the URL when the system is redirecting or a user clicks on a email confirmation link? Any information and/or examples you can share would be greatly appreciated.

    Thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    What kind of redirect, can you explant it in detail?

  • User Avatar
    0
    balessi75 created

    When I go to tenant1.domain.net, I can see while debugging, that the custom tenant resolver finds the proper tenant based on the 'tenant1' sub domain.

    The problem is that when I go to sign in, I'm properly authenticated against the tenant 'tenant1', but when the following occurs at the end of the login process...

    return Redirect(GetRedirectUrl(returnUrl, returnUrlHash));

    ...I'm sent back to the domain.net instead of tenant1.domain.net which is the URL I originally accessed to login. This causes the login screen to show up again after properly authenticating against tenant1.domain.net.

    The 'returnUrl' parameter comes from Volo.Abp.Account.Public.Web.Pages.Account.AccountPageModel.

    Also, when a 'forgot password' email is sent with a confirmation link, the link generated always points back to the domain.net URL instead of the tenant1.domain.net URL that was used when clicking the 'Forgot Password' link.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I could not reproduce the problem.

    Also, when a 'forgot password' email is sent with a confirmation link, the link generated always points back to the domain.net URL instead of the tenant1.domain.net URL that was used when clicking the 'Forgot Password' link.

    You can update the SelfUrl, for example:

    "SelfUrl": "https://{{tenantName}}.localhost:44327",

  • User Avatar
    0
    balessi75 created

    Hi @liangshiwei,

    Thanks for verifying, the login issue had to do with something on our end that we corrected.

    But we were hoping to get more information about the link sent to emails such as the 'Forgot Password' link.

    We tried... "SelfUrl": "https://{{tenantName}}.localhost:44327",

    ...but that didn't work. How and were does the {{tenantName}} placeholder get put into the SelfUrl? Is there another step? Also, we extended the tenant entity to have a "host" column for subdomain resolution. We tried replacing {{tenantName}} with {{host}} but that didn't work either.

  • User Avatar
    0
    balessi75 created

    Hi @liangshiwei,

    I was able to get the "SelfUrl" templated correctly based on our needs by overriding....

    Volo.Abp.UI.Navigation.UrlsAppUrlProvider

    Thank you, I'll close this issue.

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