Giter VIP home page Giter VIP logo

Comments (4)

JonPSmith avatar JonPSmith commented on June 5, 2024

Hi @ccnicholls99,

If your think this though you will see that you can inject the users ID via the constructor of your implementation of your ITenantChangeService.

from authpermissions.aspnetcore.

ccnicholls99 avatar ccnicholls99 commented on June 5, 2024

Hi @ccnicholls99,

If your think this though you will see that you can inject the users ID via the constructor of your implementation of your ITenantChangeService.

That was the first thing I tried. Unfortunately, at the point where the Tenant is created, you don't yet have access to the User for whom you are creating the Tenant.

See AuthPermissions.SupportCode.AddUsersServices.SignInAndCreateTenant.SignUpNewTenantWithVersionAsync()...

  • The Tenant is created first. The TenantChangeService is invoked during this call.
  • At this point, the owning AuthUser has not been created

...so injecting UserId yields null (or Non-Tenanted Admin if tenant is being created by an admin).

At the moment, I am working around this by updating any created assets manually, after the tenant is created. Not a deal breaker but another code dependency where I have to make sure the code gets updated in two places instead of one.

IMHO, it would be preferable if SignUpNewTenantWithVersionAsync deferred the call to the TenantChangeService until AFTER both the tenant and owning Auth User are created.

from authpermissions.aspnetcore.

JonPSmith avatar JonPSmith commented on June 5, 2024

Hi @ccnicholls99,

OK, I can think of two ways to do this with the ISignInAndCreateTenant service:

  1. The simplest approach is to log the user's Email and and the Tenant's name via the two DTO classes once the SignUpNewTenantWithVersionAsync have finished successfully.
  2. If you need more info, such as the user's ID, then after the SignUpNewTenantWithVersionAsync has finished successfully, then the new user has been registered. You can get user's email from the AddNewUserDto class. You can get that user via the IAuthUsersAdminService's FindAuthUserByEmailAsync method and the tenant name via the AddNewTenantDto and IAuthTenantAdminService's QueryTenants, which returns a IQueryable<Tenant> result.

Remember, you can always wrap a service with your own service, or build your own version of a service and use that instead (but in the case of the SignInAndCreateTenant I don't suggest building your code!)

PS. The ISignInAndCreateTenant service doesn't setup the user until the tenant has been successfully created. This is done so that if there is a problem, then the user can try again. NOTE: The SignInAndCreateTenant class has LOT of code to undo things if things goes wrong, especially with sharding multi-tenant app, but even then there can problems.

from authpermissions.aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.