fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
https://fullstackhero.net/dotnet-webapi-boilerplate/
MIT License
5.07k stars 1.52k forks source link

How to access the current User ? #711

Closed anasseb closed 2 years ago

anasseb commented 2 years ago

Hello, Is there a way to access the current user in both API (Application layer) and Front (any component) ? Thanks.

fretje commented 2 years ago

On the api side, there's ICurrentUser:

https://github.com/fullstackhero/dotnet-webapi-boilerplate/blob/main/src/Core/Application/Common/Interfaces/ICurrentUser.cs

On the blazor side, nothing special is done. The standard way of accessing the user in blazor is by injecting a Task<AuthenticationState> AuthState. Look at the profile page (and most other pages actually) for an example.

anasseb commented 2 years ago

Thank you, that helps me.