Skip to content

Instantly share code, notes, and snippets.

@pawelel
Last active November 23, 2021 11:14
Show Gist options
  • Save pawelel/197cb04b184f137488d6cfd72a443032 to your computer and use it in GitHub Desktop.
Save pawelel/197cb04b184f137488d6cfd72a443032 to your computer and use it in GitHub Desktop.
Get current user data without tracking by UserManager
[CascadingParameter] private Task<AuthenticationState> AuthSP { get; set; }
[Inject] private NavigationManager NavigationManager { get; set; }
string UserId;
ApplicationUser CurrentUser = new();
private async Task RedirectToLogin()
{
var user = (await AuthSP).User;
if (!user.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("Identity/Account/Login", true);
}
else
{
UserId = user.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).First().Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment