Multiple Enterprise User field

Hi Guys,

Thanks for providing such a powerful tool!

I am attempting a multi enterprise tool where all companies are sharing the same database. Every application user has a companyID field, linking him to his company's records. Then on every query the results are returned only for his company data.

My current challenge is that I would like the name (and later logo) of his company to be displayed in the header as such:

My first challenge is getting the companyID there. I added a label with value: ${Security.user.companyID}
But as you would expect I am getting an error, because the user has not yet been authenticated.
I assume you would need to test ${Security.IsAuthenticated()} before trying to retrieve the value. I am still trying to figure out how to do that in the pipe, but I suspect it is not going to help, because the label won't necessarily be re-evaluated when the user has logged in.

My second challenge is then to do a query on the Customer by this retrieved ID so that I may display the Company name.

Could you please give me some guidance ?

Kind regards
Riaan

Hi @Riaan_Havenga,

Welcome to Radzen community!

You can set ${Security.IsAuthenticated()} for the Label Visible property - in this case you will not get error if the user is still not authenticated. The same expression can be used in Condition for Data Source Method Invoke action to get customers - the invoke will be executed only if the user us authenticated.

Please check also our CRM tutorial for other techniques similar to these:

Best Regards,
Vladimir

Hi Vladimir,

Thanks for your prompt reply, but I have already tried using the IsAuthenticated flag,
image
and it gives the following error, when rendering, before login:

dotnet: info: Microsoft.AspNetCore.Hosting.Diagnostics[1]

  •  Request starting HTTP/1.1 GET http://localhost:5000/_blazor?id=WdWsxGsAvbrX8DmxRwNwnw  *
    

dotnet: info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]

  •  Executing endpoint '/_blazor'*
    

dotnet: info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]

  •  Authorization failed.*
    

dotnet: warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]

  •  Unhandled exception rendering component: Value cannot be null. (Parameter 'email')*
    

System.ArgumentNullException: Value cannot be null. (Parameter 'email')

  • at Microsoft.AspNetCore.Identity.UserManager`1.FindByEmailAsync(String email)*

dotnet: fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]

  •  Unhandled exception in circuit 'j5hGEzyebxZdL8RXirAq5L1lMmZQ7wifnDsENMnf320'.*
    

System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'email'))

  • ---> System.ArgumentNullException: Value cannot be null. (Parameter 'email')*
  • at Microsoft.AspNetCore.Identity.UserManager`1.FindByEmailAsync(String email)*
  • --- End of inner exception stack trace ---*

All the users do have Email fields defined. If I replace the Text field of the label with regular text, it starts normally.

The error in Visual Studio gives me the idea that it still tries to read the user even with the IsAuthenticated check:

I really hope you can put me on the right track.

Kind Regards
Riaan

The exception you are getting happens because Principal.Identity.Name seems to be null. Normally this should contain the user name of the logged in user. We are not sure why this isn't the case in your application.

Hi Korchev,

I have concluded that the problem is lying with the visible attribute=${Security.IsAuthenticated()} for labels, headings etc. Because the system is attempting to read Principal.Identity.Name before the user has logged in, even though I have added the said visibility check.
But it is working when I embed the label into a container like a Panel or a Card.

So thanks for your help, I am satisfied with having the Label inside a Card.

Kind Regards
Riaan