-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.razor
47 lines (42 loc) · 1.67 KB
/
App.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@using Chaos.Models.DbModels
@using Microsoft.AspNetCore.Identity
@using System.Security.Claims
@using Chaos.Shared
@inject AuthenticationStateProvider authenticationStateProvider
@inject SignInManager<GameUser> signInManager
@inject UserManager<GameUser> userManager
<CascadingAuthenticationState>
<CascadingValue Value="@loggedUserId" Name="LoggedUserId">
<CascadingValue Value="@username" Name="Username">
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<NotAuthorizedPage />
</NotAuthorized>
<Authorizing>
<h1>Authorization in progress...</h1>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<NotFoundPage />
</NotFound>
</Router>
</CascadingValue>
</CascadingValue>
</CascadingAuthenticationState>
@code
{
string loggedUserId = "";
string username = "";
protected override async Task OnInitializedAsync()
{
var authState = await authenticationStateProvider.GetAuthenticationStateAsync();
if (signInManager.IsSignedIn(authState.User))
{
loggedUserId = authState.User.Claims.Where(u => u.Type == ClaimTypes.NameIdentifier).FirstOrDefault()?.Value;
username = (await userManager.FindByIdAsync(loggedUserId)).UserName;
}
}
}