Created
April 11, 2021 19:47
-
-
Save Ibro/82631dad8156fb86dbc8900aa319000c to your computer and use it in GitHub Desktop.
Connect4 - Live game with SignalR and Blazor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IndexComponent: ComponentBase | |
{ | |
private IdentityUser _currentUser; | |
[Inject] | |
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } | |
[Inject] | |
protected UserManager < IdentityUser > UserManager { get; set; } | |
protected override async Task OnInitializedAsync() | |
{ | |
await base.OnInitializedAsync(); | |
_currentUser = await GetUser(); | |
} | |
private async Task < IdentityUser > GetUser() | |
{ | |
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); | |
var claimsPrincipal = authState.User; | |
var user = await UserManager.GetUserAsync(claimsPrincipal); | |
return user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment