M-Corp
M-Corp

Reputation: 138

Blazor - Server Side web app displaying current user Profile to new user

I have a Blazor server side web app which I am using to manage client data. A user logs in with a username and password which is validated against a sql server data base. Once logged in they have access to their profile and various functions. This all works fine.

The issue I have is that when user A logs in and then User B accesses the site the site opens with User A's profile logged in and if user B logs off the profile on their machine then User A gets kicked out. This works the same if User B logs in with their profile and then User A accesses the site.

I am new to Blazor so I approached this project as I would a normal web application. It seems a new instance of the app isn't being created on each machine.

What am I doing wrong or is there something I am missing ?

Thanks

Upvotes: 0

Views: 770

Answers (1)

Nicola Biada
Nicola Biada

Reputation: 2800

Check how you have declared/instanced your services.
If you have a service with a lifetime like singleton, all your users will share the same data returned from the service.

Look at https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-5.0&pivots=server#service-lifetime-1

Try to verify in your startup file what's and of lifetime scope have you applied.

Upvotes: 1

Related Questions