Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created April 11, 2021 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ibro/82631dad8156fb86dbc8900aa319000c to your computer and use it in GitHub Desktop.
Save Ibro/82631dad8156fb86dbc8900aa319000c to your computer and use it in GitHub Desktop.
Connect4 - Live game with SignalR and Blazor
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