Skip to content

Commit 0e29b25

Browse files
committed
Use AuthenticationStateProvider instead of HttpContext for AuthInfo
1 parent dc1df46 commit 0e29b25

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@page "/AboutMe"
2-
@using Microsoft.AspNetCore.Http
32
@inject AppConfiguration appConfiguration
4-
@inject IHttpContextAccessor httpContextAccessor
3+
@inject AuthenticationStateProvider authenticationStateProvider
54
@* TODO: Meta Tags About Me - [Name here] *@
65

76
@if (appConfiguration.IsAboutMeEnabled)
@@ -10,7 +9,7 @@
109
<div class="container">
1110
<div class="row">
1211
<div class="col-lg-3 col-md-4">
13-
<Profile IsAuthenticated="@httpContextAccessor.HttpContext.User.Identity.IsAuthenticated"/>
12+
<Profile IsAuthenticated="@isAuthenticated"/>
1413
</div>
1514
<div class="col-lg-9 col-md-8 tab-container">
1615
<div class="row">
@@ -19,4 +18,19 @@
1918
</div>
2019
</div>
2120
</div>
21+
}
22+
23+
@code {
24+
25+
private bool isAuthenticated;
26+
27+
protected override async Task OnInitializedAsync()
28+
{
29+
var userIdentity = (await authenticationStateProvider.GetAuthenticationStateAsync()).User.Identity;
30+
if (userIdentity != null)
31+
{
32+
isAuthenticated = userIdentity.IsAuthenticated;
33+
}
34+
}
35+
2236
}

0 commit comments

Comments
 (0)